Is there a PHP function that would 'pop' first element of array? array_pop()
pops last element, but I'd like to pop the first.
array_pop() pops an element off end of the array. array_push() pushes an element into the end of the array.
array_pop() pops and returns the value of the last element of array , shortening the array by one element. Note: This function will reset() the array pointer of the input array after use.
There are several methods to get the first element of an array in PHP. Some of the methods are using foreach loop, reset function, array_slice function, array_values, array_reverse, and many more. We will discuss the different ways to access the first element of an array sequentially.
shift() The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.
You are looking for array_shift().
PHP Array Shift
Quick Cheatsheet If you are not familiar with the lingo, here is a quick translation of alternate terms, which may be easier to remember:
* array_unshift() - (aka Prepend ;; InsertBefore ;; InsertAtBegin ) * array_shift() - (aka UnPrepend ;; RemoveBefore ;; RemoveFromBegin ) * array_push() - (aka Append ;; InsertAfter ;; InsertAtEnd ) * array_pop() - (aka UnAppend ;; RemoveAfter ;; RemoveFromEnd )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With