array_any()
Polyfill for array_any() added in PHP 8.4.
Checks if any element of an array passes a given callback.
No Hooks.
Returns
true|false. True if any element in the array passes the $callback, otherwise false.
Usage
array_any( $array, $callback ): bool;
- $array(array) (required)
- The array to check.
- $callback(callable) (required)
- The callback to run for each element.
Changelog
| Since 6.8.0 | Introduced. |
array_any() array any code WP 7.0
function array_any( array $array, callable $callback ): bool { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
foreach ( $array as $key => $value ) {
if ( $callback( $value, $key ) ) {
return true;
}
}
return false;
}