wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



array_any › WordPress Function

Seit6.8.0
Veraltetn/v
array_any ( $array, $callback )
Parameter: (2)
  • (array) $array The array to check.
    Erforderlich: Ja
  • (callable) $callback The callback to run for each element.
    Erforderlich: Ja
Gibt zurück:
  • (bool) True if any element in the array passes the `$callback`, otherwise false.
Definiert in:
Codex:

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

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


Quellcode

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