Re: Converting array keys to variables?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, November 17, 2006 10:23 am, Ashley M. Kirchner wrote:
>     [hours] => Array
>         (
>             [0] => Array
>                 (
>                     [file] => capture.0400.jpg
>                     [path] => spool/.2006/11/17/04
>                     [year] => 2006
>                     [month] => 11
>                     [day] => 17
>                     [hhmm] => 0400
>                 )
...
>     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:

foreach($array['hours'] as $key => $image_meta){
  list($file, $path, $year, $month, $day, $hhmm) = $image_meta;
  //Do whatever you want with the variables.
}

I personally would avoid 'extract' function, as a matter of principle,
as it's to easy to add something to an array and not realize it, and
then you start over-writing variables you didn't mean to, because your
key name matches some other variable you didn't mean to over-write...

YMMV

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux