(PHP 8 >= 8.5.0)
array_first — Gets the first value of an array
array
An array.
Returns the first value of array
if the array is not empty;
null
otherwise.
示例 #1 Basic array_first() Usage
<?php
$array = [1 => 'a', 0 => 'b', 3 => 'c', 2 => 'd'];
$firstValue = array_first($array);
var_dump($firstValue);
?>
以上示例会输出:
string(1) "a"