array_first( array $array )

Polyfill for array_first() function added in PHP 8.5.


Description

Returns the first element of an array.


Parameters

$array

(Required) The array to get the first element from.


Return

(mixed|null) The first element of the array, or null if the array is empty.


Source

File: wp-includes/compat.php

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

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

Changelog

Changelog
Version Description
6.9.0 Introduced.