Use the PHP array_unshift() function
You can use the PHP array_unshift()
function to insert one or more elements or values to the beginning of an array.
Let’s check out an example to see how it works:
1 2 3 4 5 6 7 8 9 10 11 |
<?php $skills = array("HTML5", "CSS3", "JavaScript"); // Prepend array with new items array_unshift($skills, "Illustrator", "Photoshop"); echo "<pre>"; print_r($skills); ?> |
Output:
1 2 3 4 5 6 7 8 9 10 |
Array ( [0] => Illustrator [1] => Photoshop [2] => HTML5 [3] => CSS3 [4] => JavaScript ) |