Php array insert value at any position, php array insert

Source: Internet
Author: User

Php array insert value at any position, php array insert

Array_splice ()

$ Arr = array ('A', 'B', 'C ');

$ Arr2 = 'abc ';
$ T = array_splice ($ arr, 1, 0, $ arr2 );

Print_r ($ arr );

Console output:

Array ([0] => 'A' [1] => 'abc' [2] => 'B' [3] => 'C ');

A Brief Introduction to the array_splice method,Parameter 1 is the array to be operated, parameter 2 is the index value of the operation element, parameter 3 is the length, and parameter 4 is the element to be replaced.

The effect of this method is to delete the coherent elements with a length of 0 starting from 1 in $ arr and then add them with $ arr2.

Tips: If the length is 0, the effect is equivalent to inserting the specified element at the specified index value.

-------------------------------------------------------------- Gorgeous split line oo00o0ooo0oo... ---------------------__________________________

The above array_splice is a pig,

Array_push

Array_push -- push one or more units to the end of the array (into the stack)

Description int Array_push(Array & array, mixed var [, mixed...])

Array_push ()SetArrayAs a stack, and the input variables are pushedArray.ArrayThe length will increase according to the number of variables in the stack. The effect is the same as the following:

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.