时间:2021-07-01 10:21:17 帮助过:20人阅读
$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);