Adding Elements in an Array
In this lesson, we will learn about adding elements at the start, end and in between an array
Adding Elements at the Start #
Sometimes you want to add an element to the beginning of an array without modifying any of the current elements within the array. Whenever this is the case, you can use array_unshift()
function.
array_unshift()
prepends passed elements at the front of an array. Note that the list of elements is prepended as a whole so that the prepended elements stay in the same order. All numerical array keys will be modified to start counting from 0.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy