array_all()
Polyfill for array_all() added in PHP 8.4.
Checks if all elements of an array pass a given callback.
No Hooks.
Returns
true|false. True if all elements in the array pass the $callback, otherwise false.
Usage
array_all( $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_all() array all code WP 6.9.1
function array_all( array $array, callable $callback ): bool { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
foreach ( $array as $key => $value ) {
if ( ! $callback( $value, $key ) ) {
return false;
}
}
return true;
}