Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

array_all

Checks whether every element satisfies a condition.

Syntax

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

Parameters

ParameterTypeDescription
$arrayarrayThe input array.
$callbackcallableA test function: receives the value and the key.

Return value

bool`true` if the function returned `true` for every element.

Examples

Are all marks passing:

<?php
 
var_dump(array_all([4, 5, 3], fn ($mark) => $mark >= 3));
var_dump(array_all([4, 2, 5], fn ($mark) => $mark >= 3));

Output:

bool(true)
bool(false)

Notes

The function appeared in PHP 8.4. For an empty array the result is true.

See also

  • array_any — Checks whether at least one element satisfies a condition.
  • array_find — Returns the first element for which the function returned true.
  • array_filter — Keeps the array elements that pass a test.

Related recipes

In the tutorial

  • New in PHP 8.4 — PHP 8.4 features — property hooks, asymmetric visibility, calling a method right after new, and new array functions.

Thanks for reading!

Donate to the site — we work hard for you.