wpseek.com
A WordPress-centric search engine for devs and theme authors



array_any › WordPress Function

Since6.8.0
Deprecatedn/a
array_any ( $array, $callback )
Parameters: (2)
  • (array) $array The array to check.
    Required: Yes
  • (callable) $callback The callback to run for each element.
    Required: Yes
Returns:
  • (bool) True if any element in the array passes the `$callback`, otherwise false.
Defined at:
Codex:

Polyfill for `array_any()` function added in PHP 8.4.

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


Source

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