Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active August 27, 2020 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/5260d26e4bfdb799dc97348c7a060e44 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/5260d26e4bfdb799dc97348c7a060e44 to your computer and use it in GitHub Desktop.
Just PHP FUN 087.
<?php
function deep_c(array $a): int {
$x = 0;
foreach($a as $v){
$x+= 1;
if(is_array($v)) $x += deep_c($v);
}
return $x;
}
# https://www.codewars.com/kata/596f72bbe7cd7296d1000029 Array Deep Count.
/*
You should not use the PHP built-in count() function
Failed asserting that '<?php function deep_c(array $a): int {\n
$counter = 0;\n
foreach($a as $v){\n
$counter += 1;\n
if(is_array($v)) $counter += deep_c($v);\n
}\n
return $counter;\n
}' does not match PCRE pattern "/count/i".
*/
function deep_c(array $a): int {
$counter = 0;
foreach($a as $v){
$counter += 1;
if(is_array($v)) $counter += deep_c($v);
}
return $counter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment