[PHP] Converting array keys to variables?
I have an array that looks like this: [hours] = Array ( [0] = Array ( [file] = capture.0400.jpg [path] = spool/.2006/11/17/04 [year] = 2006 [month] = 11 [day] = 17 [hhmm] = 0400 ) [1] = Array ( [file] = capture.0500.jpg [path] = spool/.2006/11/17/05 [year] = 2006 [month] = 11 [day] = 17 [hhmm] = 0500 ) ) Is there a way that I can simply loop through each array and convert the keys into variables? I want to avoid having to write lines of: $file = $array[0][file]; $path = $array[0][path]; $year = $array[0][year]; $month = $array[0][month]; $day = $array[0][day]; $hhmm = $array[0][hhmm]; -- A -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Imaging . 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting array keys to variables?
Is there a way that I can simply loop through each array and convert the keys into variables? I want to avoid having to write lines of: Look into extract(). http://us3.php.net/manual/en/function.extract.php thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting array keys to variables?
On Fri, 2006-11-17 at 09:23 -0700, Ashley M. Kirchner wrote: I have an array that looks like this: [hours] = Array ( [0] = Array ( [file] = capture.0400.jpg [path] = spool/.2006/11/17/04 [year] = 2006 [month] = 11 [day] = 17 [hhmm] = 0400 ) [1] = Array ( [file] = capture.0500.jpg [path] = spool/.2006/11/17/05 [year] = 2006 [month] = 11 [day] = 17 [hhmm] = 0500 ) ) Is there a way that I can simply loop through each array and convert the keys into variables? I want to avoid having to write lines of: $file = $array[0][file]; $path = $array[0][path]; $year = $array[0][year]; $month = $array[0][month]; $day = $array[0][day]; $hhmm = $array[0][hhmm]; ?php extract( $array[0] ); ? Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting array keys to variables?
Ashley M. Kirchner wrote: I have an array that looks like this: [hours] = Array ( [0] = Array ( [file] = capture.0400.jpg [path] = spool/.2006/11/17/04 [year] = 2006 [month] = 11 [day] = 17 [hhmm] = 0400 ) [1] = Array ( [file] = capture.0500.jpg [path] = spool/.2006/11/17/05 [year] = 2006 [month] = 11 [day] = 17 [hhmm] = 0500 ) )\ foreach ($yourArr['hours'] as $data) { /* now just reference the values in the array $data e.g. */ $img = file_get_contents($data['path'].'/'.$data['file']); echo $data['hhmm'],' ',$data['day'],'-',$data['month'],'-',$data['year']; } the idea is to avoid copying data into variables when it's not needed ... Is there a way that I can simply loop through each array and convert the keys into variables? I want to avoid having to write lines of: $file = $array[0][file]; $path = $array[0][path]; $year = $array[0][year]; $month = $array[0][month]; $day = $array[0][day]; $hhmm = $array[0][hhmm]; where the are your quotes for the array keys? have an E_NOTICE or six. -- A -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting array keys to variables?
Jochem Maas wrote: $file = $array[0][file]; $path = $array[0][path]; $year = $array[0][year]; $month = $array[0][month]; $day = $array[0][day]; $hhmm = $array[0][hhmm]; where the are your quotes for the array keys? have an E_NOTICE or six. I was typing fast and didn't bother to put them in when I was composing my e-mail. They did exist in the actual code, though it's now a moot point as I'm not doing it that way anymore. :) Thanks for bringing it up though. -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Imaging . 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php