Asked • 05/14/19

Get the first element of an array in PHP?

I have an array: `array( 4 => 'apple', 7 => 'orange', 13 => 'plum' )` I would like to get the first element of this array. Expected result: <i>string</i> `apple` One requirement: *it cannot be done with passing by reference*, so `array_shift` is not a good solution. How can I do this?

1 Expert Answer


Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.