Get the first element of an array

后端 未结 30 2030
醉酒成梦
醉酒成梦 2020-11-22 10:59

I have an array:

array( 4 => \'apple\', 7 => \'orange\', 13 => \'plum\' )

I would like to get the first element of this array. Expect

30条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 11:21

    $array=array( 4 => 'apple', 7 => 'orange', 13 => 'plum' );
    
    $firstValue = each($array)[1];
    

    This is much more efficient than array_values() because the each() function does not copy the entire array.

    For more info see http://www.php.net/manual/en/function.each.php

提交回复
热议问题