Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

count

Description

The count of Array for PHP count all elements in an array, or something in an object.

Syntax

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

Parameters

value

An array or countable object.

mode

Mode for counting.

NumberConstantDescription
0COUNT_NORMALcount normally
1COUNT_RECURSIVEcount recursively

Return

Returns the number of elements in value.

Examples

1 · value · array

<?

$value = array(0, 1, 2);

$return = count($value);

echo $return;

?>
3

2 · value · Countable

<?

class myclass implements Countable
{
    protected $mycount = 3;

    public function count()
    {
        return $this->mycount;
    }
}

$value = new myclass;

$return = count($value);

echo $return;

?>
3

3 · mode · COUNT_NORMAL

<?

$value = array(0, 1, array(0, 1));
$mode = COUNT_NORMAL;

$return = count($value, $mode);

echo $return;

?>
3

4 · mode · COUNT_RECURSIVE

<?

$value = array(0, 1, array(0, 1));
$mode = COUNT_RECURSIVE;

$return = count($value, $mode);

echo $return;

?>
5
HomeMenu