Extract leaf nodes of multi-dimensional array in PHP -
Suppose my PHP has an array that looks like this
array (array 0) (array (0) (...) .... array (10) (..)) ... array (n) (array (0) ()))
< P> And I need elements of all the leaves of this movie-dimensional array in a linear array, how do I do this without such recycling? ($ Element as $ E) {if (is_array ($ e) {getChild ($ e);}}} Note: Top code snippet, extremely incomplete
update: array example
array ([0] => array ([0] = & gt; array ([0] => vendor object ([ C Redits: private] = & gt; 5000000 [Balance: Private] => 4998 9 70 [Queue: Private] => [[Seller: Private] => 2 [DateTime: Private] = & gt; ; 2009-07-25 17:53:10)))
... snipped.
[2] => Array ([ 0] = & gt; Array ([0] = & gt; Vendor object ([credit: private] => 10000000 [Balance: Private] => 9997940 [Queue: Private] => 135 [Vic] Sata: private] = & gt; 234 [datetime: private] => 2009-07-14 23:36:00)) .... snapped ....)
< P>)
Actually, there is a function that does the trick, see the manual page on it Quick snippet optimized from page:
$ data = array ('test' = & gt; array ('deep' = & gt; array ('last' = & Gt; 'Foo'), 'bar'), 'falcon'); Var_dump ($ data); Function printValue ($ value, $ of, $ userData) {// resonant "$ value \ n"; $ UserData [] = $ value; } $ Result = new ArrayObject (); Array_walk_recursive ($ data, 'printValue', $ result); Var_dump ($ result);
Comments
Post a Comment