PHP Funktion count ()
Komplette PHP - Array - Referenz
Beispiele
Gibt die Anzahl der Elemente in dem Array:
<?php
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
?>
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
?>
Ausführung einer Instanz »
Definition und Verwendung
count () Funktion, um die Anzahl der Elemente in dem Array zurückgibt.
Grammatik
count( array,mode );
参数 | 描述 |
---|---|
array | 必需。规定要计数的数组。 |
mode | 可选。规定函数的模式。可能的值:
|
Technische Details
Rückkehr: | Gibt die Anzahl der Elemente in dem Array. |
---|---|
PHP-Version: | 4+ |
Update-Protokoll: | Modus Parameter sind neu in PHP 4.2. |
Weitere Beispiele
Beispiel 1
Rekursives Berechnen der Anzahl der Elemente in dem Array:
<?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);
?>
$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);
?>
Ausführung einer Instanz »
Komplette PHP - Array - Referenz