PHP array_key_first function

Last Updated: February 13, 2022

array_key_first — Get the first key of the array

Syntax

 array_key_first(array $array): int|string|null

Supports (PHP 7 >= 7.3.0, PHP 8)

Parameters

array – the array you want to evaluate

Return Value

The first key of the array

Example



<?php
$array = ['one' => 1, 'two' => 2, 'three' => 3];

$firstKey = array_key_first($array);

var_dump($firstKey);
?>

Test