php basics
PHP array_unshift insert elements into the beginning of the array
PHP array_unshift is used to insert one or more elements or arrays at the beginning of the array, the usage is the opposite of array_shift .
PHP array_unshift syntax example
array_unshift (the original array, the element or array to be inserted);
array_unshift will insert the "element or array to be inserted" directly into the beginning of the original array, and the newly inserted element or array is a whole group insertion, and there will be no change in itself, but the original array may be changed! The element numbers of the original array will be rearranged from zero, but the key value itself will not change, just look at the following example.
PHP array_unshift implementation syntax example
<?php
$Arr = array("C", "D");
array_unshift($Arr, "A", "B");
print_r($Arr);
?>
Output result: Array ([0] => A [1] => B [2] => C [3] => D) The$Arr = array("C", "D");
array_unshift($Arr, "A", "B");
print_r($Arr);
?>
example first prepared an array $Arr with only two elements at the beginning, and then used array_unshift to Insert A and B at the beginning of $Arr, and finally use print_r to output the processed value of the array. You can see that the output result has four elements in total, and A and B are in front, and the element number has restarted from zero.
Post a Comment
0 Comments