Php checks array length functions sizeof and count usage, sizeofcount
This example describes how to use the sizeof and count functions of php to check the array length. Share it with you for your reference. The details are as follows:
A simple example is provided below sizeof count in the php array length detection function:
Copy codeThe Code is as follows: $ colorlist = array ("apple" => "red", "grass" => "green", "sky" => "blue ", "night" => "black", "wall" => "white ");
Echo "array length:". count ($ colorlist); // 5
Count: The count () function calculates the number of units in an array or the number of attributes in an object. For an array, the number of elements is returned. For other values, 1 is returned, if the parameter is a variable but the variable is not defined, 0 is returned. If the mode is set to count_recursive (OR 1), the number of elements in the array in the multi-dimensional array is calculated recursively.
Sizeof: definition and usage. The sizeof () function calculates the number of units in the array or the number of attributes in the object.
Syntax: sizeof (array, mode)
| Parameters |
Description |
| Array |
Required. specifies the array or object to be counted. |
| Mode |
Optional. specifies the function mode. Possible values: 0-default. Multi-dimensional arrays are not detected. arrays in the array. 1-multi-dimensional array detection. |
Note: The mode parameter is added to php 4.2.
Prompt count sizeof
Note: If the variable is not set or contains an empty array, the function returns 0. You can use the isset () variable to test whether the variable is set.
I hope this article will help you with PHP programming.