日期:2014-05-17 浏览次数:20706 次
$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);