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



array_first › WordPress Function

Since6.9.0
Deprecatedn/a
array_first ( $array )
Parameters:
  • (array) $array The array to get the first element from.
    Required: Yes
Returns:
  • (mixed|null) The first element of the array, or null if the array is empty.
Defined at:
Codex:

Polyfill for `array_first()` function added in PHP 8.5.

Returns the first element of an array.


Source

function array_first( array $array ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
		if ( empty( $array ) ) {
			return null;
		}

		foreach ( $array as $value ) {
			return $value;
		}
	}
}