In PHP, it is common to add elements like arrays to the Array_push function, which is the stack operation of the array, but the function is to add elements to the end of the array, if you need to press the array elements into the array's head (that is, the first element) how to do it?
Using the PHP built-in function Array_unshift, here's a list of array_unshift the function.
Array_unshift
The function is to insert one or more elements at the beginning of the array. The added elements are added as a whole, and the elements in the array are in the same order as in the arguments. All numeric key names in the modified array are modified to count back from zero, and all text key names remain unchanged. The function returns the number of elements in the array after the operation.
Syntax: int array_unshift (array & $array, mixed $var [, mixed $ ...]
For example:
The above routines will output:
Array
(
[0] = Apple
[1] = Raspberry
[2] = Phpernote
[3] = =. com
)
Articles you may be interested in
- PHP finds whether a value exists in the array (In_array (), Array_search (), array_key_exists ())
- Two-dimensional arrays remove duplicate values and Array_unique functions
- PHP Merge array + vs. Array_merge
- PHP generates consecutive numbers (Letters) array function range () analysis, PHP lottery program function
- PHP gets all the files in the directory and saves the results to an array of programs
- The method of rounding exact decimal digits and rounding in PHP
- How PHP removes the first and last elements of an array
- JS inserts the element to the front of the body element of the method
http://www.bkjia.com/PHPjc/764084.html www.bkjia.com true http://www.bkjia.com/PHPjc/764084.html techarticle in PHP, it is common to add elements like arrays to the Array_push function, which is the stack operation of the array, but the function is to add elements to the end of the array, if you need to press the array elements ...