Php Array Elements Unshift Function

What is array_unshift Function?

Explanation

The "array_unshift" function prepend one or more elements to the beginning of an array.

Syntax:


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

In the above syntax "array" is the array in which the "Value1", Value2", "Value3" are prepended to the begining of an array.

Example :


<?php
$a=array("a"=>"Orange","b"=>"Guava");
print_r(array_unshift($a,"Cherry"));
?>
Result :

Array ( [0] => Cherry [a]=> Orange [b]=> Guava );

In the above example the value,"Cherry" is added to the begining of the array.The key for that value is numerical [0].

PHP Topics


Ask Questions

Ask Question