Example 1 — Testing Every Number
Pass an array and a callback. The result is a single true or false.
<?php
$even = [2, 4, 6, 8];
$mixed = [2, 4, 5];
var_dump(array_all($even, fn($n) => $n % 2 === 0));
var_dump(array_all($mixed, fn($n) => $n % 2 === 0)); How It Works
- The callback fn($n) => $n % 2 === 0 is true for even numbers.
- Every item in $even is even, so the first call returns true.
- In $mixed the value 5 is odd, so the callback returns false for it.
- One failing item is enough, so the second call returns false.

