多维表长度

时间:2014-05-25 11:05:25

标签: php

我有下面的数组会更大:

$numbers = array(
array(1,2,3,5,9,8,6),
array(1,5,7,2,3,0),
array(2,5,9,25,78,89)
);

如何获得数组中数组的长度?

2 个答案:

答案 0 :(得分:1)

看看这里,

<?php
$food = array('fruits' => array('orange', 'banana', 'apple'),
          'veggie' => array('carrot', 'collard', 'pea'));

// recursive count
echo count($food, COUNT_RECURSIVE); // output 8

// normal count
echo count($food); // output 2

?>

答案 1 :(得分:0)

试试这个 -

$numbers = array( 
            array(1,2,3,5,9,8,6), 
            array(1,5,7,2,3,0), 
            array(2,5,9,25,78,89)
         );
echo count($numbers);  // Count of outer array ==> 2


$counts = array();
foreach($numbers as $number)
{
    $counts[] = count($number);
}

print_r($counts);  // Array of count of inner
echo array_sum($counts);  // Total Count of inner arrays ==> 19