Signatur
count(Countable|array $value, int $mode = COUNT_NORMAL): int
Beschreibung
Mit COUNT_RECURSIVE werden verschachtelte Arrays mitgezählt. Alias: sizeof().
Parameter
| Name | Typ | Default | Beschreibung |
|---|---|---|---|
| $value Pflicht | array|Countable | — | Zu zählendes Objekt/Array. |
| $mode | int | COUNT_NORMAL | COUNT_NORMAL oder COUNT_RECURSIVE. |
Rückgabewert
Typ
int
Beschreibung
Anzahl Elemente.
Beispiele
Basis
<?php
echo count(['a', 'b', 'c']); // 3
Rekursiv
<?php
$data = [[1,2], [3,4,5]];
echo count($data, COUNT_RECURSIVE); // 7 (2 Sub-Arrays + 5 Elemente)