- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
array_unshift() function in PHP
The array_unshift() function adds one or more elements to the beginning of an array.
Syntax
array_unshift(arr, val1, val2, val3)
Parameters
arr − The specified array. Required.
val1 − Value to be inserted. Required.
val2 − Value to be inserted. Optional.
val3 − Value to be inserted. Optional.
Return
The array_unshift() function returns the new elements in the array.
Example
The following is an example −
<?php $arr = array("p"=>"one","q"=>"two"); print_r(array_unshift($arr,"three")); ?>
Output
The following is the output −
3
Example
Let us see another example −
<?php $arr = array("p"=>"one","q"=>"two"); array_unshift($arr,"three"); print_r($arr); ?>
Output
The following is the output −
Array ( [0] => three [p] => one [q] => two )
Advertisements