Rumah > Artikel > pembangunan bahagian belakang > php关于count函数求解释解决方案
php关于count函数求解释
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$food = array('fruits' => array('orange', 'banana', 'apple'), 'veggie' => array('carrot', 'collard', 'pea')); // recursive count echo count($food, COUNT_RECURSIVE); // output 8
$food = array( 'fruits' => array('orange', 'banana', 'apple'), 'veggie' => array('carrot', 'collard', 'pea'));function leay_count($ar) { $r = 0; foreach($ar as $item) { if(is_array($item)) $r += leay_count($item); else $r++; } return $r;}echo leay_count($food);<div class="clear"> </div>