array_all( array $array, callable $callback )
Polyfill for array_all() function added in PHP 8.4.
Description
Checks if all elements of an array pass a given callback.
Parameters
- $array
-
(Required) The array to check.
- $callback
-
(Required) The callback to run for each element.
Return
(bool) True if all elements in the array pass the $callback, otherwise false.
Source
File: wp-includes/compat.php
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;
}
Changelog
| Version | Description |
|---|---|
| 6.8.0 | Introduced. |