php array length detection function sizeof and count usage, sizeofcount
The example in this article describes the usage of PHP array length detection function sizeof and count. Share it with everyone for your reference. The details are as follows:
The function to detect the length of an array in PHP is sizeof count. Here is a simple example:
Copy code The code is as follows:
$colorlist = array("apple"=>"red", "grass"=>"green" ,"sky"=>"blue","night"=>"black","wall"=>"white");
echo "The length of the array is: ".count($colorlist); //5
count:count() function counts the number of cells in an array or the number of attributes in an object. For an array, it returns the number of its elements. For other values, it returns 1. If the parameter is a variable and the variable is not defined, it returns 0. If mode is set to count_recursive (or 1), the number of elements in the array in the multidimensional array will be calculated recursively.
sizeof: Definition and usage, the sizeof() function calculates the number of cells in an array or the number of attributes in an object.
Syntax: sizeof(array,mode)
Parameters |
Description |
array |
Required, specifies the array or object to be counted. |
mode |
Optional, specifies the mode of the function, possible values:
参数 |
描述 |
array |
必需,规定要计数的数组或对象. |
mode |
可选,规定函数的模式,可能的值:
0 - 默认.不检测多维数组,数组中的数组.
1 - 检测多维数组。 |
0 - Default. Do not detect multi-dimensional arrays, arrays within arrays.
1 - Detect multidimensional arrays.
|
Note: The parameter mode was added in php 4.2.
Tip count sizeof
Note: When the variable is not set, or the variable contains an empty array, this function will return 0. You can use the isset() variable to test whether the variable is set.
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/912677.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/912677.htmlTechArticlePHP detects the array length function sizeof and count usage, sizeofcount This article describes the use of PHP array length detection function sizeof and count . Share it with everyone for your reference. The details are as follows:...