How to add elements to the beginning of an array in PHP
In this post we will give you information about How to add elements to the beginning of an array in PHP. Hear we will give you detail about How to add elements to the beginning of an array in PHPAnd how to use it also give you demo for it if it is necessary.
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);
?>
Hope this code and post will helped you for implement How to add elements to the beginning of an array in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs