It is very simple to get the length of an array in PHP. PHP provides us with two functions to calculate the length of a one-dimensional array, such as count and sizeof, which can directly count the length of the array. Let's take a look at a few examples.
How to get the length of an array in php, use php function count(), or sizeof()
For example:
The code is as follows
代码如下 |
复制代码 |
$arr = Array('0','1','2','3','4');
echo count($arr);
// 输出 5
$arr = array('A','B','C');
echo sizeof($arr);
//输出3
|
|
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. You can get the number of elements in a regular scalar variable. If the array passed to this function is an empty array, or For a variable that has not been set, the number of array elements returned is 0;
The functions of the two functions are the same. According to the manual, sizeof() is an alias of the function count().
So how to count the length of multi-dimensional arrays?
You can refer to: http://www.bKjia.c0m/phper/21/32805.htm
http://www.bkjia.com/PHPjc/632682.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632682.htmlTechArticleIt is very simple to get the length of an array in PHP. PHP provides us with two functions to calculate the length of a one-dimensional array. , such as count and sizeof, can directly count the array length. Let’s take a look...