Home > Backend Development > PHP Tutorial > Several ways to get the length of an array in php_PHP tutorial

Several ways to get the length of an array in php_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:49:56
Original
1018 people have browsed it

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:

echo sizeof($arr);
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');

//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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template