How to use array unshift in PHP
In this article, I will explain how the array_unshift() function can be used in PHP.
array_unshift() function in PHP
-
The array_unshift() function is used to inserts one or more new elements to an array.
-
In array_unshift() function, the new array values will be inserted in the beginning of the array.
-
array_unshift() function's return value is the new number of elements in the array.
Syntax
array_unshift(array,value1,value2,value3....) |
Parameter
-
array array is required parameter. Specifies an array.
-
value1 value1 is required parameter. value1 to be added in array.
-
value2 value2 is optional parameter. value2 to be added in array.
-
value3 value3 is optional parameter. value3 to be added in array.
Example
The following example show to how the array_unshift() function can be used in PHP.
<html>
<body>
<h3 style="color: steelblue;">array_unshift() function example in PHP</h3>
<?php
$list = array('Priyanka','Nitin');
array_unshift($list, 'Ravi','Richa');
print_r($list);
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here