3v4l.org

run code in 300+ PHP versions simultaneously
<?php $finalresult = array ( 101 => array( "username"=> "1st user", "children"=> array ( 104=> array ( "username"=> "4th user", "children"=> array() ), 105=> array ( "username"=> "5th user", "children"=> array() ), 108=> array ( "username"=> "new guy", "children"=> array() ) ) ), 102=> array ( "username"=> "2nd user", "children"=> array() ), 103=> array ( "username"=> "3rd user", "children"=> array() ) ); function count_children($tree) { $count = 0; foreach ($tree as $child) { $count++; if (is_array($child['children'])) { $count += count_children($child['children']); } } return $count; } echo count_children($finalresult);

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
161.44 ms | 3295 KiB | 9 Q