PHP count() Funktion
Beispiel
Gibt die Anzahl der Elemente in einem Array zurück:
<?php
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
?>
Definition und Verwendung
Die Funktion count() gibt die Anzahl der Elemente in einem Array zurück.
Syntax
count(array, mode)
Parameterwerte
Parameter | Description |
---|---|
array | Required. Specifies the array |
mode | Optional. Specifies the mode. Possible values:
|
Technische Details
Rückgabewert: | Gibt die Anzahl der Elemente im Array zurück |
---|---|
PHP-Version: | 4+ |
PHP-Änderungsprotokoll: | Der Mode-Parameter wurde in PHP 4.2 hinzugefügt |
Mehr Beispiele
Beispiel
Zählen Sie das Array rekursiv:
<?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);
?>
❮ PHP-Array-Referenz