PHP sizeof() 函數(shù)
PHP sizeof() 函數(shù)
定義和用法
sizeof() 函數(shù)返回數(shù)組中元素的數(shù)目。
sizeof() 函數(shù)是 count() 函數(shù)的別名。
語法
sizeof(array,mode);
參數(shù) | 描述 |
---|---|
array | 必需。規(guī)定要計數(shù)的數(shù)組。 |
mode | 可選。規(guī)定函數(shù)的模式??赡艿闹担?ul>
|
技術細節(jié)
返回值: | 返回數(shù)組中元素的數(shù)目。 |
---|---|
PHP 版本: | 4+ |
更多實例
實例 1
遞歸地計算數(shù)組中元素的數(shù)目:
<?php
$cars=array
(
"Volvo"=>array
(
"XC60",
"XC90"
),
"BMW"=>array
(
"X3",
"X5"
),
"Toyota"=>array
(
"Highlander"
)
);
echo "Normal count: " . sizeof($cars)."<br>";
echo "Recursive count: " . sizeof($cars,1);
?>
$cars=array
(
"Volvo"=>array
(
"XC60",
"XC90"
),
"BMW"=>array
(
"X3",
"X5"
),
"Toyota"=>array
(
"Highlander"
)
);
echo "Normal count: " . sizeof($cars)."<br>";
echo "Recursive count: " . sizeof($cars,1);
?>
運行實例 ?
