wpseek.com
WordPress开发者和主题制作者的搜索引擎



array_first › WordPress Function

Since6.9.0
已弃用n/a
› array_first ( $array )
参数:
  • (array) $array The array to get the first element from.
    Required: Yes
返回:
  • (mixed|null) The first element of the array, or null if the array is empty.
定义在:
文档:

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

Returns the first element of an array.


源码

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

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