This article describes the PHP detection array length function sizeof and count usage. Share to everyone for your reference. Specifically as follows:
In PHP, the function that detects the length of an array has sizeof count below to see a simple example:
Copy Code code as follows:
$colorlist = Array ("Apple" => "red", "Grass" => "green", "Sky" => "Blue", "Night" => "Black" and "wall" => "white" );
echo "Array length:". Count ($colorlist); 5
The Count:count () function computes the number of cells in an array or the number of attributes in an object, returns the number of elements for an array, returns 1 for other values, and returns 0 if the argument is a variable and the variable is undefined, and if mode is set to Count_recursive (or 1), The number of elements of an array in a multidimensional array is recursively computed.
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 |
Describe |
Array |
Required, specify the array or object to count. |
Mode |
Optionally, specify the mode of the function, the possible values: 0-Default. Multidimensional arrays are not detected, arrays in the array. 1-detects multidimensional arrays. |
Note: Parameter mode is added in PHP 4.2.
Tip Count sizeof
Note: When the variable is not set, or if the variable contains an empty array, the function returns 0, and you can use the Isset () variable to test whether the variable is set.
I hope this article will help you with your PHP program design.