当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > sizeof() 函数
The sizeof() function counts the elements of an array, or the properties of an object.
sizeof()函数的作用是:统计一个数组中所包含的元素数量;或者是统计一个对象中所包含的属性数量。
This function is an alias of the count() function.
sizeof()函数是count()函数的替代函数。
sizeof(array1,array2) |
| Parameter 参数 | Description 描述 |
|---|---|
| array | Required. Specifies the array or object to count. 必要参数。指定需要被统计数量的函数或对象 |
| mode | Optional. Specifies the mode of the function. Possible values: 可选参数。指定执行模式。下面列出可使用的参数:
Note: This parameter was added in PHP 4.2 |
Note: This function may return 0 if a variable isn't set, but it may also return 0 if a variable contains an empty array. The isset() function can be used to test if a variable is set.
注意:如果变量不存在或者变量为空值,那么该函数都将返回“0”。Isset()函数可以用来测试变量是否存在。
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
$result = sizeof($people);
echo $result;
?>
|
The output of the code above will be:
上述代码将输出下面的结果:
4 |
评论 (0) All