PHP array_key_first()Function
Complete PHP Array Reference Manual
Examples
Get the first key of the array:
$array = ['a' => 1, 'b' => 2, 'c' => 3];
$firstKey = array_key_first($array);
echo $firstKey;
Execute the above code, the output is:
a
Definition and Usage
The array_key_first() function is used to get the first key of the specified array.
Gets the first key of the specified array without affecting the internal pointer of the original array.
Syntax
array_key_first ( array $array ) : mixed
| Parameters | Description |
|---|---|
| array | The array to be operated on. |
Technical Details
| Return Value: | Returns the first key of the array (if not empty), otherwise returns null. |
|---|---|
| PHP Version: | PHP 7 >= 7.3.0, PHP 8 |
Other Extensions