array_key_first()WP 5.9.0

Get the first key of the given array without affecting the internal array pointer.

No Hooks.

Return

String|Int|null. The first key of array if the array is not empty; null otherwise.

Usage

array_key_first( $arr );
$arr(array) (required)
An array.

Changelog

Since 5.9.0 Introduced.

Code of array_key_first() WP 6.0

function array_key_first( array $arr ) {
	foreach ( $arr as $key => $value ) {
		return $key;
	}
}