PHP count() Functie
Voorbeeld
Retourneer het aantal elementen in een array:
<?php
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
?>
Definitie en gebruik
De functie count() retourneert het aantal elementen in een array.
Syntaxis
count(array, mode)
Parameterwaarden
Parameter | Description |
---|---|
array | Required. Specifies the array |
mode | Optional. Specifies the mode. Possible values:
|
Technische details
Winstwaarde: | Retourneert het aantal elementen in de array |
---|---|
PHP-versie: | 4+ |
PHP-wijzigingslogboek: | De modusparameter is toegevoegd in PHP 4.2 |
Meer voorbeelden
Voorbeeld
Tel de array recursief:
<?php
$cars=array
(
"Volvo"=>array
(
"XC60",
"XC90"
),
"BMW"=>array
(
"X3",
"X5"
),
"Toyota"=>array
(
"Highlander"
)
);
echo "Normal count: " . count($cars)."<br>";
echo "Recursive count: " . count($cars,1);
?>
❮ Referentie voor PHP-array