array_traverse

From: Date: Mon, 02 Jul 2001 20:11:44 +0000
Subject: array_traverse
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-55895@lists.php.net to get a copy of this message
Here's a little function i use to traverse an array of arbitrary complexity... it uses recursion. function array_traverse ($ary, $b=array()) { while ( list($k,$v) = each($ary) ) { print (join("", $b)) . "$k = $v\n"; array_push($b, "\t"); if ( is_array($ary[$k]) ) { array_traverse($ary[$k], $b); } array_pop($b); } return 1; } with the data: $x = array( '1'=> array( 'one' => 'first', ), '2'=> array( 'two' => 'second', 'second'=> 'two', ) ); it will print: 1 = Array one = first 2 = Array two = second second = two

« previous php.general (#55895) next »