Easy Tutorial
❮ Func Array Key Exists Func Filesystem Feof ❯

PHP array_key_first() Function

Complete PHP Array Reference Manual

Example

Get the first key of an array:

<?php
$array = ['a' => 1, 'b' => 2, 'c' => 3];

$firstKey = array_key_first($array);

echo $firstKey;
?>

Executing the above code will output:

a

Definition and Usage

The array_key_first() function is used to get the first key of a specified array.

It retrieves the first key of the given array without affecting the internal pointer of the array.


Syntax

array_key_first ( array $array ) : mixed
Parameter Description
array The array to operate 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
--- ---

Complete PHP Array Reference Manual

❮ Func Array Key Exists Func Filesystem Feof ❯