array_first()WP 6.9.0

Polyfill for array_first() added in PHP 8.5.

Returns the first element of an array.

No Hooks.

Returns

Mixed|null. The first element of the array, or null if the array is empty.

Usage

array_first( $array );
$array(array) (required)
The array to get the first element from.

Changelog

Since 6.9.0 Introduced.

array_first() code WP 6.9

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

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