How to use array unshift in PHP

In this article, I will explain how the array_unshift() function can be used in PHP.
  • 2002

array_unshift() function in PHP

  • The array_unshift() function is used to inserts one or more new elements to an array.

  • In array_unshift() function, the new array values will be inserted in the beginning of the array.

  • array_unshift() function's return value is the new number of elements in the array.




  • array  array is required parameter. Specifies an array.

  • value1 value1 is required parameter. value1 to be added in array.

  • value2 value2 is optional parameter. value2 to be added in array.

  • value3 value3 is optional parameter. value3 to be added in array.


The following example show to how the array_unshift() function can be used in PHP.



<h3 style="color: steelblue;">array_unshift() function example in PHP</h3>  


    $list = array('Priyanka','Nitin'); 

    array_unshift($list, 'Ravi','Richa'); 








You may also want to read these related articles here
Ask Your Question 
Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.