array_unshift(): Adding one element at starting of the array
$output=array_unshift($input);
To add one or more element at the beginning of the array. After applying array_unshift() total elements of the array increases by one or more . All numerical array keys are re-indexed but literal keys remain same.
Returns the total number of elements present (after adding using array_unshift() to the array.)
Here $input is an array, $output get the value of total number of elements of the array.
$input=array('One','Two','Three','Four','Five');
$output=array_unshift($input,'added_now');
echo $output; // Output is 6
echo "<br><br>";
while (list ($key, $val) = each ($input)) {
echo "$key -> $val <br>";
}
Output of above code is here( $output gets the number of elements present 6 )
6
0 -> added_now
1 -> One
2 -> Two
3 -> Three
4 -> Four
5 -> Five
To add more than one element we will change the code like this.