PHP 8.5.0 RC4 available for testing

array_first

(PHP 8 >= 8.5.0)

array_firstRenvoie la première valeur d'un tableau

Description

array_first(array $array): mixed

Renvoie la première valeur du array donné.

Liste de paramètres

array
Un tableau.

Valeurs de retour

Renvoie la première valeur du array donné si le tableau n'est pas vide; sinon null.

Exemples

Exemple #1 Utilisation basique de array_first()

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

$firstValue = array_first($array);

var_dump($firstValue);
?>

L'exemple ci-dessus va afficher :

string(1) "a"

Voir aussi

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top