array_key_first( array $arr )

Polyfill for array_key_first() function added in PHP 7.3.


Description

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


Top ↑

Parameters

$arr

(array) (Required) An array.


Top ↑

Return

(string|int|null) The first key of array if the array is not empty; null otherwise.


Top ↑

Source

File: wp-includes/compat.php

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

Top ↑

Changelog

Changelog
Version Description
5.9.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.