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
Syntax
array_any(array $array, callable $callback): bool
Parameters
| Parameter | Description |
|---|---|
array |
The input array. |
callback |
fn($value, $key) returns true for a match. |
Return value
true if any element matches.
Examples
<?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.
<?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
| Version | Change |
|---|---|
| PHP 8.4 | Added |
In other languages
any()· Pythonarray.some()· JavaScript
Related
array_all()· Return true if every element passes a callback test, stopping at the first failure. Added in PHP 8.4.array_find()· Return the first element for which a callback returns true, or null if none match. Added in PHP 8.4.in_array()· Check whether a value exists in an array. Pass true as the third argument for a strict (===) comparison.- PHP Array Functions · tutorial
- PHP Arrays · tutorial