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)

It specifies an array.

2

value1(Required)

It specifies a value to insert

3

value2(Optional)

It specifies a value to insert

4

value3(Optional)

It specifies a value to insert

Example

Try out following example −

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

This will produce the following result −

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

php_function_reference.htm

Advertisements