PHP sizeof() 函数
PHP 教程
· 2019-01-22 22:58:59
实例
返回数组中元素的数目:
<?php
$cars=array("Volvo","BMW","Toyota");
echo sizeof($cars);
?>
$cars=array("Volvo","BMW","Toyota");
echo sizeof($cars);
?>
定义和用法
sizeof() 函数返回数组中元素的数目。
sizeof() 函数是 count() 函数的别名。
语法
sizeof(array,mode);
| 参数 | 描述 |
|---|---|
| array | 必需。规定要计数的数组。 |
| mode | 可选。规定函数的模式。可能的值:
|
技术细节
| 返回值: | 返回数组中元素的数目。 |
|---|---|
| PHP 版本: | 4+ |
更多实例
实例 1
递归地计算数组中元素的数目:
<?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);
?>
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
The Nature of Code
Daniel Shiffman / The Nature of Code / 2012-12-13 / GBP 19.95
How can we capture the unpredictable evolutionary and emergent properties of nature in software? How can understanding the mathematical principles behind our physical world help us to create digital w......一起来看看 《The Nature of Code》 这本书的介绍吧!