I want to learn how to use recursive functions, so I started to create one:
<?php
$tableau = [[[[2],[2]],[[2],[2]]],[[[2],[2]],[[2],[2]]]];
function test_count_recursive($tab, $compte = 0){
foreach($tab as $ss_tab){
if(!is_array($ss_tab)){
$compte += 1;
}
else{
test_count_recursive($ss_tab, $compte);
}
}
return $compte;
}
echo test_count_recursive($tableau);
But it doesn't work, can you tell me why?