note 80352 added to function.count

From: Date: Fri, 11 Jan 2008 09:20:19 +0000
Subject: note 80352 added to function.count
Groups: php.notes 
Request: Send a blank email to php-notes+get-135024@lists.php.net to get a copy of this message
Here is an iterative soloution of danny's count_recursive function which might be more efficient due to the missing recursion <?php /** * counts elements of an multidimensional array * * @param array $array Input Array * @param int $limit dimensions that shall be considered (-1 means no limit ) * @return int counted elements */ function multicount ($array, $limit = -1) { $cnt = 0; $limit = $limit > 0 ? (int) $limit : -1; $arrs[] = $array; for ($i=0; isset($arrs[$i]) && is_array($arrs[$i]); ++$i) { foreach ($arrs[$i] as $value) { if (!is_array($value) ) ++$cnt; elseif( $limit==-1 || $limit>1 ) { if( $limit>1 ) --$limit; $arrs[] = $value; } } } return $cnt; } ?> ---- Server IP: 212.124.37.9 Probable Submitter: 88.73.75.46 ---- Manual Page -- http://www.php.net/manual/en/function.count.php Edit -- https://master.php.net/note/edit/80352 Del: integrated -- https://master.php.net/note/delete/80352/integrated Del: useless -- https://master.php.net/note/delete/80352/useless Del: bad code -- https://master.php.net/note/delete/80352/bad+code Del: spam -- https://master.php.net/note/delete/80352/spam Del: non-english -- https://master.php.net/note/delete/80352/non-english Del: in docs -- https://master.php.net/note/delete/80352/in+docs Del: other reasons-- https://master.php.net/note/delete/80352 Reject -- https://master.php.net/note/reject/80352 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135024) next »