Home>Article>Backend Development> How to query the length of an array in php
How to query the length of an array in php: 1. Use the php function "count()" to get the length of the array. The syntax is such as "count($arr);"; 2. Use the "sizeof()" function to get the length of the array. To calculate the length of an array, the syntax is "sizeof($arr);".
Recommended: "PHP Video Tutorial"
The method to get the length of an array in php is very simple, php does it for us Two functions are provided 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 the php function count(), or sizeof()
For example:
$arr = Array('0','1','2','3','4'); echo count($arr); // 输出 5 $arr = array('A','B','C'); echo sizeof($arr); //输出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 a variable that has not been set, the returned The number of array elements is 0;
The two functions have the same function. According to the manual, sizeof() is an alias of the function count().
The above is the detailed content of How to query the length of an array in php. For more information, please follow other related articles on the PHP Chinese website!