How to query the length of an array in php

藏色散人
Release: 2023-03-04 08:00:01
Original
3615 people have browsed it

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);".

How to query the length of an array in php

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
Copy after login

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!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template