array_first
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.5.0)
Gets the first value of an array
Description
array_first(array $array): mixed
Get the first value of the given array.
Parameters
arrayAn array.
Return Values
Returns the first value of array if the array is not empty; null otherwise.
Examples
Basic array_first() Usage
php
<?php
$array = [1 => 'a', 0 => 'b', 3 => 'c', 2 => 'd'];
$firstValue = array_first($array);
var_dump($firstValue);
?>The above example will output:
output
string(1) "a"