wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema



array_first › WordPress Function

Desde6.9.0
Obsoleton/a
› array_first ( $array )
Parâmetros:
  • (array) $array The array to get the first element from.
    Required: Yes
Retorna:
  • (mixed|null) The first element of the array, or null if the array is empty.
Definido em:
Codex:

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

Returns the first element of an array.


Fonte

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

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