Re: Funny array function

From: Date: Sun, 30 Sep 2012 12:03:42 +0000
Subject: Re: Funny array function
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-63250@lists.php.net to get a copy of this message
kuldeep dhaka wrote: > /* > i was thinking if is their any function that can do the above work like > */ > echo array_drill($array, > array("school","class","roll_number","name")); The following should work: function array_drill($array, $keys) { while (($key = array_shift($keys)) !== null) { $array =& $array[$key]; } return $array; } (Not tested. It will fail if the key doesn't exist, you can optionally check that and fail however you'd like.) -- Ryan McCue <http://ryanmccue.info/>

« previous php.internals (#63250) next »