Home  >  Article  >  Backend Development  >  What does count mean in php?

What does count mean in php?

青灯夜游
青灯夜游Original
2019-10-17 13:50:235350browse

What does count mean in php?

count is a built-in function in PHP. The count() function returns the number of elements in the array.

Syntax:

count(array,mode);

Parameters:

array: required. Specifies an array.

mode: optional. Specify the mode. Possible values:

● 0 - Default. Do not count all elements in a multidimensional array

 ● 1 - Recursively count the number of elements in the array (count all elements in a multidimensional array)

Description:

count() function counts the number of cells in an array or the number of attributes in an object.

For an array, return the number of its elements, for other values, return 1; if the parameter is a variable and the variable is not defined, return 0.

If mode is set to COUNT_RECURSIVE (or 1), the number of elements in the array in the multidimensional array will be calculated recursively.

Example:

<?php
header("content-type:text/html;charset=utf-8");
$cars = array("Volvo" => array("XC60", "XC90"), 
              "BMW" => array("X3", "X5"), 
              "Toyota" => array("Highlander")
		);

echo "常规计数:" . count($cars) . "<br>";
echo "递归计数:" . count($cars, 1);
?>

Result:

常规计数:3
递归计数:8

For more PHP related knowledge, please visit php中文网!

The above is the detailed content of What does count mean 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