[php]count — 計算陣列中的單元數目或對象中的屬性個數

官方範例1
<?php
$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
$result = count($a);
// $result == 3

$b[0] = 7;
$b[5] = 9;
$b[10] = 11;
$result = count($b);
// $result == 3;

$result = count(null);
// $result == 0

$result = count(false);
// $result == 1
?>

官方範例2
Example #2 count() 的遞歸例子(PHP >= 4.2.0)
<?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
?>


arrow
arrow
    全站熱搜

    stockwfj3 發表在 痞客邦 留言(0) 人氣()