Php can be used to obtain the length of an array. The method for getting the array length in php is very simple. php provides two functions for us to calculate the length of one-dimensional arrays, such as count and sizeof, the method for getting the array length in php is very simple. php provides two functions for us to calculate the length of one-dimensional arrays, such as count and sizeof, let's take a look at several instances.
How does php obtain the length of an array? use the php function count () or sizeof ()
For example:
| The code is as follows: |
|
$ Arr = Array ('0', '1', '2', '3', '4 '); Echo count ($ arr ); // Output 5 $ Arr = array ('A', 'B', 'C '); Echo sizeof ($ arr ); // Output 3 |
Sizeof () and count () have the same purpose. both functions can return the number of array elements. we can get the number of elements in a regular scalar variable. If the array passed to this function is an empty array or an unspecified variable, the number of returned array elements is 0;
The two functions are the same. in the manual, sizeof () is the alias of the function count.
How can we calculate the length of a multi-dimensional array?
Please refer to: http://www.bKjia. c0m/phper/21/32805 .htm
...