Get the first element of an array

后端 未结 30 2074
醉酒成梦
醉酒成梦 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:33

    current($array) can get you the first element of an array, according to the PHP manual.

    Every array has an internal pointer to its "current" element, which is initialized to the first element inserted into the array.

    So it works until you have re-positioned the array pointer, and otherwise you'll have to reset the array using reset()

提交回复
热议问题