wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



array_first › WordPress Function

Depuis6.9.0
Dépréciéen/a
› array_first ( $array )
Paramètres:
  • (array) $array The array to get the first element from.
    Requis: Oui
Retourne:
  • (mixed|null) The first element of the array, or null if the array is empty.
Défini(e) dans:
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;
		}
	}
}