array_key_first

(PHP 7 >= 7.3.0)

array_key_firstGets the first key of an array

说锟斤拷

array_key_first ( array $array ) : mixed

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

锟斤拷锟斤拷

array

An array.

锟斤拷锟斤拷值

Returns the first key of array if the array is not empty; NULL otherwise.

锟斤拷锟斤拷

Example #1 Basic array_key_first() Usage

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

$firstKey array_key_first($array);

var_dump($firstKey);
?>

锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�

string(1) "a"

锟轿硷拷

  • array_key_last() - Gets the last key of an array
  • reset() - 锟斤拷锟斤拷锟斤拷锟斤拷诓锟街革拷锟街革拷锟斤拷一锟斤拷锟斤拷元