Blog de programación, errores, soluciones

Chose Language:
Author: Admin/Publisher |finished | checked

PHP array_key_first function

This function retrieves the first key of the provided array. It does not affect the pointer’s position within the array.

Description / Descripción
array_key_first(array $array): int | string | null


$array – the array provided


Returns the first key of the array if it is not empty; otherwise, it will return null.


The following example is a simple one with car brands:

$marcasDeAutos = array(

When could you use array_key_first? Well, it depends on whether you want to treat the first element differently or not. Not always in an array are the elements of equal importance. For example, the first element could be the title, or maybe you want to do something visual, like the header in a blog post that displays whether it’s internally checked, the author, whether it’s completed, and if there’s a peer review.
Category: en-php
Something wrong? If you found an error or mistake in the content you can contact me on Twitter | @luisg2249_luis.
Last 4 post in same category