Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

sizeof()

This alias of count measures the number of elements or the count supplied by a Countable object.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

sizeof(Countable|array $value, int $mode = COUNT_NORMAL): int

This alias of count measures the number of elements or the count supplied by a Countable object. COUNT_RECURSIVE includes nested array members as well as their containers. It does not measure memory in bytes. A string argument causes TypeError in PHP 8.

Signature

sizeof(Countable|array $value, int $mode = COUNT_NORMAL): int

Example output

[2,4,1]

Examples

<?php
$rows = ["a"=>[1,2],"b"=>[]];
echo json_encode([sizeof($rows),sizeof($rows,COUNT_RECURSIVE),sizeof(new ArrayObject([9]))]);

Result

[2,4,1]

Sources