array_first()

array_first() — Gets the first value of an array.

Built-in function of PHP 8.5. The manual lists it as available in PHP 8 >= 8.5.0. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

array_first(array $array): mixed

Parameters

ParameterTypeWhat it takes
$arrayarrayAn array.

Return value

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

Example

A runnable snippet:

$array = [1 => 'a', 0 => 'b', 3 => 'c', 2 => 'd']; $firstValue = array_first($array); var_dump($firstValue);

Output:

string(1) "a"

See also

array_key_first(), array_last()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page array_first() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.