温馨提示×

php怎么统计数组元素个数

PHP
小亿
82
2024-02-28 17:40:28
栏目: 编程语言

要统计数组元素个数,可以使用PHP中的count()函数。

示例代码如下:

$array = array(1, 2, 3, 4, 5);
$count = count($array);
echo "数组元素个数为: " . $count;

运行上述代码,会输出:

数组元素个数为: 5

count()函数还可以用来计算多维数组的元素个数,只需要将数组作为参数传递给count()函数即可。

0