Home >Backend Development >PHP Problem >How to determine how many values ​​an array has in php

How to determine how many values ​​an array has in php

青灯夜游
青灯夜游Original
2021-05-18 17:57:043530browse

In PHP, you can use the count() function to determine how many values ​​an array has; this function can count the number of elements in the array and return the number of elements. The syntax format is "count(array) ", its parameter array represents the array to be counted. When using it, you only need to pass the array into array.

How to determine how many values ​​an array has in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use count () function to determine how many values ​​an array has.

$arr = Array('0','1','2','3','4');
echo count($arr); // 输出 5

Output:

5

Description:

count(): Count the number of elements in the array Perform statistics and return the number of elements in the array.

Syntax

count(array,mode);
Parameters Description
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).

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to determine how many values ​​an array has in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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