Php array_unshift adds elements to the array

Source: Internet
Author: User
Php array_unshift adds an element to the array. The array_unshift () function inserts one or more elements at the beginning of the array. Array_unshift (array, value1, value2, value3. ..) array is required. Specifies the input array. Value1 is required. Specifies the value to be inserted. Value2 is optional. Specifies the value to be inserted. Value3 is optional. Specifies the value to be inserted. Before array_unshift (), add the first element array. Note that the listed elements are prepended as a whole, so that the preset content remains in the same order. The keys in all numeric arrays are modified to count from scratch, while the text keys remain unchanged. Here is an array_unshift instance."Cat", "B" => "Dog"); print_r (array_unshift ($ a, "Horse");?> The output value is 3array_unshift. The array has a numeric key:"Cat", 1 => "Dog"); array_unshift ($ a, "Horse"); print_r ($ a);?> Output: Array ([0] => Horse [1] => Cat [2] => Dog) instance 3Array ([0] => apple [1] => raspberry [2] => orange [3] => banana)

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.