Getting the array length method in PHP is simple, PHP provides us with two functions to calculate the length of one-dimensional array, such as count,sizeof can be directly statistical array length Oh, let's look at a few examples.
How PHP Gets the length of the array, using 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 of which can return the number of array elements. You can get the number of elements in a regular scalar variable, if the array passed to the function is an empty array, or is an array of variables that are not set, the number of elements returned is 0;
Like the function of two functions, the manual says that sizeof () is the alias of the function count ().
So how to count the length of multidimensional arrays?
Please refer to: http://www.bKjia.c0m/phper/21/32805.htm
http://www.bkjia.com/PHPjc/632682.html www.bkjia.com true http://www.bkjia.com/PHPjc/632682.html techarticle getting the array length method in PHP is simple, PHP provides us with two functions to calculate the length of a one-dimensional array, such as count,sizeof can be directly statistical array length Oh, let's see ...