note 71015 modified in function.count by danbrown

From: Date: Fri, 09 Jan 2009 23:00:23 +0000
Subject: note 71015 modified in function.count by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149012@lists.php.net to get a copy of this message
My function returns the number of elements in array for multidimensional arrays subject to depth of array. (Almost COUNT_RECURSIVE, but you can point on which depth you want to plunge). <?php function getArrCount ($arr, $depth=1) { if (!is_array($arr) || !$depth) return 0; $res=count($arr); foreach ($arr as $in_ar) $res+=getArrCount($in_ar, $depth-1); return $res; } ?> --was-- My function returns the number of elements in array for multidimensional arrays subject to depth of array. (Almost COUNT_RECURSIVE, but you can point on which depth you want to plunge). <? function getArrCount ($arr, $depth=1) { if (!is_array($arr) || !$depth) return 0; $res=count($arr); foreach ($arr as $in_ar) $res+=getArrCount($in_ar, $depth-1); return $res; } ?> http://php.net/manual/en/function.count.php

« previous php.notes (#149012) next »