Example 1 — Looking for One Match
Pass an array and a callback. The result is true when any item passes the test.
<?php
$withEven = [1, 3, 5, 6];
$onlyOdd = [1, 3, 5];
var_dump(array_any($withEven, fn($n) => $n % 2 === 0));
var_dump(array_any($onlyOdd, fn($n) => $n % 2 === 0)); How It Works
- The callback fn($n) => $n % 2 === 0 is true for even numbers.
- $withEven contains 6, which is even, so the first call returns true.
- $onlyOdd has no even number, so the callback is never true.
- After checking every item without a match, the second call returns false.

