• In PHP this unbuilt function is used to count the current elements in the array.
  • If it has been set to an empty array, whether the function might return 0 for the variable and the variable that is not set the function returns 0.
  • Generally, this function takes one parameter, the array for which the elements need to be counted.
  • The function an take a parameter mode which tells the function to count the element in recursive or normal mode but in addition.
  • In Count () syntax $array is mandatory and in which elements are needed to be counted.
  • In Count () mode is optional which is used to set the mode of function and their parameter can take two possible values, either 0 or 1. 1 generally indicates to count of the values of the array recursively.
  • In an array, the functions return the number of elements.

Syntax

Count ($array, mode)

Sample Code

<!DOCTYPE html>
<html>
<body>

<?php
$cars=array("Volvo","Volkswagen","Hyundai","Ferrari");
echo count($cars);
?>

</body>
</html>

Output

Categorized in: