Monday, 26 August 2013

PHP Function array_unshift()

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.

Paramters

ParameterDescription
arrayRequired. Specifies an array.
value1Required. Specifies a value to insert
value2Optional. Specifies a value to insert
value3Optional. 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 following result:
Array
(
    [0] => apple
    [1] => raspberry
    [2] => orange
    [3] => banana
)

No comments:

Post a Comment