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

array_all

Description

The array_all of Array for PHP checks if all array.

Syntax

array_all(
    array $array,
    callable $callback
): mixed

Parameters

array

The array that should be searched.

callback

The callback function to call to check each element, which must be

callback(
    mixed $value,
    mixed $key
): bool

If this function returns false, false is returned from array_all() and the callback will not be called for further elements.

Return

Returns true if callback returns true for all elements. Otherwise, the function returns false.

Examples

1 · array callback · false

<?

function callback(string $value, $key)
{
    return $key === $value[0];
}

$array =
[
    "a" => "dog",
    "b" => "cat",
    "c" => "cow"
];
$callback = "callback";

$return = array_all($array, $callback);

var_dump($return);
bool(false)

2 · array callback · true

<?

function callback(string $value, $key)
{
    return $key === $value[0];
}

$array =
[
    "a" => "ape",
    "b" => "bird",
    "c" => "cow"
];
$callback = "callback";

$return = array_all($array, $callback);

var_dump($return);
bool(true)