wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



array_any › WordPress Function

Depuis6.8.0
Dépréciéen/a
› array_any ( $array, $callback )
Paramètres: (2)
  • (array) $array The array to check.
    Requis: Oui
  • (callable) $callback The callback to run for each element.
    Requis: Oui
Retourne:
  • (bool) True if any element in the array passes the `$callback`, otherwise false.
Défini(e) dans:
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;
	}
}