incrementing recursive reference fails [SOLUTION: RTFM!]
Posted: Tue Mar 06, 2007 7:30 am
Bit nervous about this but here goes ....
What do you think this prints?
Because I get $index nicely incrementing in PHP version 5.1.0 and not in 5.2.0.
Any changes I should know about (couldn't spot any in the changelogs) or more likely, any idiocy on my part?
(Installing 5.2.1 now to have a look)
What do you think this prints?
Code: Select all
$tree = array ('val' => '-root-', 'children' => array (
1 => array ('val' => 'one', 'children' => array (
2 => array ('val' => 'two', 'children' => array ()))),
3 => array ('val' => 'three', 'children' => array (
4 => array ('val' => 'four', 'children' => array ())))));
function prarray ($tree, &$index=null) {
print "\n ".$index.' '.$tree['val'];
foreach($tree['children'] as $subtree)
prarray($subtree, ++$index);
}
prarray($tree,$i=0);Any changes I should know about (couldn't spot any in the changelogs) or more likely, any idiocy on my part?
(Installing 5.2.1 now to have a look)