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



array_all › WordPress Function

Seit6.8.0
Veraltetn/v
array_all ( $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 all elements in the array pass the `$callback`, otherwise false.
Definiert in:
Codex:

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

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


Quellcode

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