Q:

How to add elements to the beginning of an array in PHP

0

How to add elements to the beginning of an array in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

<?php
$skills = array("HTML5", "CSS3", "JavaScript");
 
// Prepend array with new items
array_unshift($skills, "Illustrator", "Photoshop");
print_r($skills);
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to add elements to the end of an array in PHP... >>
<< How to remove the first element from an array in P...