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



array_all › WordPress Function

Since6.8.0
Deprecatedn/a
array_all ( $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 all elements in the array pass the `$callback`, otherwise false.
Defined at:
Codex:

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

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


Source

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