count in PHP

Syntax of count in PHP

int count(mixed value[, int mode])

Returns the number of elements in the value; for arrays or objects, this is the number of elements; for any other value, this is 1. If the parameter is a variable and the variable is not set, 0 is returned. If mode is set and is COUNT_RECURSIVE, the number of elements is counted recursively, counting the number of values in arrays inside arrays.

Example of count in PHP

<?php
$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));
?>
int(3)
int(3)

Leave a Comment