sizeof()
sizeof() — Alias of count().
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
sizeof() is an alias of count(): same parameters, same return value.
Signature
sizeof(Countable|array $value, int $mode = COUNT_NORMAL): int
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $value | Countable|array | An array or Countable object. |
| $mode | int | If the optional mode parameter is set to COUNT_RECURSIVE (or 1), count() will recursively count the array. This is particularly useful for counting all the elements of a multidimensional array. |
Return value
Returns the number of elements in value. Prior to PHP 8.0.0, if the parameter was neither an array nor an object that implements the Countable interface, 1 would be returned, unless value was null, in which case 0 would be returned.
Example
A runnable snippet:
$a[0] = 1; $a[1] = 3; $a[2] = 5; var_dump(count($a)); $b[0] = 7; $b[5] = 9; $b[10] = 11; var_dump(count($b));
Output:
int(3) int(3)
All PHP 8.5 built-in functions
Reference card built from the PHP manual page sizeof() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.