Re: Converting array keys to variables?
| From: | Richard Lynch | Date: | Mon, 20 Nov 2006 22:55:18 +0000 |
| Subject: | Re: Converting array keys to variables? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244908@lists.php.net to get a copy of this message | ||
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?