PHP 8 reference · Array Functions

PHP array_all() Function

Return true if every element passes a callback test, stopping at the first failure. Added in PHP 8.4.

PHP 8 Since 8.4

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

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

Parameters

ParameterDescription
array The input array.
callback fn($value, $key) returns true if the element passes.

Return value

true if all elements pass.

Examples

Are all adults?
<?php
$ages = [21, 34, 19];
var_dump(array_all($ages, fn($age) => $age >= 18));

Output

bool(true)

Run this on your computer — see “Get Started” for setup.

Empty arrays
<?php
var_dump(array_all([], fn($v) => false)); // empty: true

Output

bool(true)

Run this on your computer — see “Get Started” for setup.

Version history

VersionChange
PHP 8.4Added

In other languages

Was this page helpful?