PHP sizeof() 函数

PHP 教程 · 2019-01-22 22:58:59

实例

返回数组中元素的数目:

<?php
$cars=array("Volvo","BMW","Toyota");
echo sizeof($cars);
?>

定义和用法

sizeof() 函数返回数组中元素的数目。

sizeof() 函数是 count() 函数的别名。

语法

sizeof(array,mode);

参数 描述
array 必需。规定要计数的数组。
mode 可选。规定函数的模式。可能的值:
  • 0 - 默认。不计算多维数组中的所有元素。
  • 1 - 递归地计算数组中元素的数目(计算多维数组中的所有元素)。

技术细节

返回值: 返回数组中元素的数目。
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);
?>

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

The Nature of Code

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》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具