PHP 8.5.0 RC 2 available for testing

array_first

(PHP 8 >= 8.5.0)

array_firstGets the first value of an array

Descrição

array_first(array $array): mixed

Get the first value of the given array.

Parâmetros

array

An array.

Valor Retornado

Returns the first value of array if the array is not empty; null otherwise.

Exemplos

Exemplo #1 Basic array_first() Usage

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

$firstValue = array_first($array);

var_dump($firstValue);
?>

O exemplo acima produzirá:

string(1) "a"

Veja Também

adicionar nota

Notas de Usuários

Não há notas de usuários para esta página.
To Top