是否可以不迭代数组?
$arr = array(
'section1' => array(
5 => array(1, 2, 3),
25 => array(4, 5),
34 => array(10, 12),
),
'section2' => array(
45 => array(1, 42, 3),
64 => array(10, 2, 5, 95),
),
'section3' => array(
5 => array(1, 2, 3, 5, 2),
25 => array(4, 5, 14),
34 => array(17),
),
);
$count = 0;
foreach($arr as $section)
foreach($section as $subsection)
foreach($subsection as $entries)
$count++;
echo $count; // 23
它有效,但我不想遍历整个数组只是为了计算一些元素......