Skip to content

Instantly share code, notes, and snippets.

@ArtemioVegas
Created September 9, 2017 10:11
Show Gist options
  • Save ArtemioVegas/8d8f92c2e7e54589a715d75c420d5cfb to your computer and use it in GitHub Desktop.
Save ArtemioVegas/8d8f92c2e7e54589a715d75c420d5cfb to your computer and use it in GitHub Desktop.
аналог встроенной пхп функции count
<?php
function counter(array $array,$multi = 0){
$count = 0;
foreach($array as $val){
if($multi){
if(is_array($val)){
$count += counter($val,1);
}else{
++$count;
}
}else{
++$count;
}
}
return $count;
}
var_dump(counter(array(1,2,array(4,5,array(8,9,10))),1));
var_dump(counter(array(1,2,array(4,5,array(8,9,10))),0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment