array_any()WP 6.8.0

Polyfill for array_any() added in PHP 8.4.

Checks if any element of an array passes a given callback.

No Hooks.

Return

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

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