Search⌘ K
AI Features

Adding Elements in an Array

Understand how to manipulate PHP arrays by adding elements at the start with array_unshift, at the end with array_push, and at specific positions through key assignment. This lesson helps you modify arrays effectively for dynamic data handling.

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 ...