实例
返回数组中元素的数目:
<?php
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
?>
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
?>
定义和用法
count() 函数返回数组中元素的数目。
语法
count(array,mode);
参数 | 描述 |
---|---|
array | 必需。规定要计数的数组。 |
mode | 可选。规定函数的模式。可能的值:
|
技术细节
返回值: | 返回数组中元素的数目。 |
---|---|
PHP 版本: | 4+ |
更新日志: | mode 参数是在 PHP 4.2 中新增的。 |
更多实例
实例 1
递归地计算数组中元素的数目:
<?php
$cars=array
(
"Volvo"=>array
(
"XC60",
"XC90"
),
"BMW"=>array
(
"X3",
"X5"
),
"Toyota"=>array
(
"Highlander"
)
);
echo "Normal count: " . count($cars)."<br>";
echo "Recursive count: " . count($cars,1);
?>
$cars=array
(
"Volvo"=>array
(
"XC60",
"XC90"
),
"BMW"=>array
(
"X3",
"X5"
),
"Toyota"=>array
(
"Highlander"
)
);
echo "Normal count: " . count($cars)."<br>";
echo "Recursive count: " . count($cars,1);
?>
猜你喜欢:
暂无回复。