This article mainly introduces the usage of the sizeof and count functions for php array length detection. The example analyzes the usage of count and provides a detailed analysis of the sizeof function, which has some reference value, friends in need can
This article mainly introduces the usage of the sizeof and count functions for php array length detection. The example analyzes the usage of count and provides a detailed analysis of the sizeof function, which has some reference value, friends in need can
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:
The Code is as follows:
$ Colorlist = array ("apple" => "red", "grass" => "green", "sky" => "blue ", "night" => "black", "wall" => "white ");
Echo "array length:". count ($ colorlist); // 5
Count: count () function is used to calculate 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)
Parameter 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.