Get the first element of an array

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

    This is a little late to the game, but I was presented with a problem where my array contained array elements as children inside it, and thus I couldn't just get a string representation of the first array element. By using PHP's current() function, I managed this:

     array('one', 'two'), 7 => array('three', 'four'));
        reset($original);  // to reset the internal array pointer...
        $first_element = current($original);  // get the current element...
    ?>
    

    Thanks to all the current solutions helped me get to this answer, I hope this helps someone sometime!

提交回复
热议问题