Concept

How can you add elements to an array?

ComputerScienceOne / Adding Elements

"You can easily add elements to an array by providing an index and using the assignment operator as in the previous examples. There are also several functions PHP defines that can insert elements to the beginning (array_unshift()), end (array_push()) or at an arbitrary position (array_splice()).\n\n$arr = array(10, 20, 30);\n\narray_unshift($arr, 15);\n\n//arr is now [15, 10, 20, 30]\n\narray_push($arr, 25);\n\n//arr is now [15, 10, 20, 30, 25]\n\n//insert 35 at index 3:\n\narray_splice($arr, 3, 0, 35);\n\n//arr is now [15, 10, 20, 35, 30, 25]\n\nAnother, simpler way of adding elements is to use the following syntax:"

Related Ideas

How can you add elements to an array? | ComputerScienceOne | Bifalgorithm | Bifalgorithm