The method for getting the array length in php is very simple. php provides two functions for us to calculate the length of a one-dimensional array. for example, count and sizeof can both be used to calculate the array length. let's look at the following:
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 (). The instance 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.