Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

array_key_first()

Read the first key in the current iteration order without moving the internal array pointer.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

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

Read the first key in the current iteration order without moving the internal array pointer. Sorting by key can therefore change the first key without inserting anything. An empty array returns null, while key zero is a valid result and must be distinguished from absence.

Signature

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

Example output

[0,7,null]

Examples

<?php
$jobs = [0=>'open', 7=>'late'];
end($jobs);
echo json_encode([array_key_first($jobs), key($jobs), array_key_first([])]);

Result

[0,7,null]

Sources