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: |
Copy code |
|
$ 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