PHP 8 reference · Array Functions

PHP array_any() Function

Return true if at least one element passes a callback test, stopping at the first match. 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_any(array $array, callable $callback): bool

Parameters

ParameterDescription
array The input array.
callback fn($value, $key) returns true for a match.

Return value

true if any element matches.

Examples

Is anything unpaid?
<?php
$orders = [["paid" => true], ["paid" => false]];
var_dump(array_any($orders, fn($o) => !$o["paid"]));

Output

bool(true)

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

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

Output

bool(false)

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

Version history

VersionChange
PHP 8.4Added

In other languages

Was this page helpful?