PHP push elements into the array header (Array_unshift usage) _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.