PHP - Function array_unshift()


Advertisements


Syntax

array_unshift($array,$value1,$value2,$value3...)

Definition and Usage

This function returns an array containing all the values of array1 that are present in all the arguments array2, array3.

Parameters

Sr.No Parameter & Description
1

array

Required. Specifies an array.

2

value1

Required. Specifies a value to insert

3

value2

Optional. Specifies a value to insert

4

value3

Optional. Specifies a value to insert

Example

Try out following example −

<?php
   $queue = array("orange", "banana");
   array_unshift($queue, "apple", "raspberry");
   
   print_r($queue);
?> 

This will produce the following result −

Array ( [0] => apple [1] => raspberry [2] => orange [3] => banana )

php_function_reference.htm

Advertisements