Is it possible to query how many elements an array has in php?

WBOY
Release: 2023-03-15 16:50:01
Original
1788 people have browsed it

In PHP, you can use the count() function to query how many elements an array has. The return result of this function is the number of array elements, and the syntax is "count(array, mode)"; the second parameter defaults to 0, which means that the elements in the multi-dimensional array are not counted. If set to 1, the multi-dimensional array elements are calculated recursively. .

Is it possible to query how many elements an array has in php?

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

Can php query how many elements there are in an array?

Can I query how many elements there are in an array.

count() function returns the number of elements in the array.

Syntax

count(array,mode);
Copy after login

array Required. Specifies the array to count.

mode Optional. Specifies the mode of the function. Possible values:

  • 0 - Default. Not counting all elements in a multidimensional array.

  • 1 - Recursively count the number of elements in an array (count all elements in a multidimensional array).

Return value: Returns the number of elements in the array.

The example is as follows:

<?php
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
?>
Copy after login

The output result is 3.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Is it possible to query how many elements an array has in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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