|
array_unshiftPrepend one or more elements to the beginning of an array Description
int array_unshift(array
&$array , mixed ...$values )
array_unshift prepends passed elements to the front
of the
Parameters
Return Values
Returns the new number of elements in the Changelog
Examples
Example #1 array_unshift example
The above example will output: array(4) { [0] => string(5) "apple" [1] => string(9) "raspberry" [2] => string(6) "orange" [3] => string(6) "banana" }
Example #2 Usage with associative arrays If one associative array is prepended to another associative array, the prepended array is numerically indexed into the former array.
The above example will output: array(3) { [0] => array(3) { 'lettuce' => array(2) { 'Iceberg' => string(5) "green" 'Butterhead' => string(5) "green" } 'carrots' => array(2) { 'Deep Purple Hybrid' => string(6) "purple" 'Imperator' => string(6) "orange" } 'cucumber' => array(2) { 'Kirby' => string(5) "green" 'Gherkin' => string(5) "green" } } 'apples' => array(2) { 'McIntosh' => string(3) "red" 'Granny Smith' => string(5) "green" } 'oranges' => array(2) { 'Navel' => string(6) "orange" 'Valencia' => string(6) "orange" } } See Also
|