array_all()WP 6.8.0

Polyfill for array_all() added in PHP 8.4.

Checks if all elements of an array pass a given callback.

No Hooks.

Return

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() code WP 6.8

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;
}