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://www.codercto.com/courses/l/5.html

查看所有标签

You Can Program in C++

You Can Program in C++

Francis Glassborow / John Wiley & Sons / 2006-7 / 406.80元

An interactive and fun way to learn C++, one of the most popular high-level programming languages for graphic applications This unique, hands-on approach to learning C++ makes t......一起来看看 《You Can Program in C++》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

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

RGB CMYK 互转工具