Inserting values anywhere in the PHP array

Source: Internet
Author: User

Array_splice ()

$arr = Array (' A ', ' B ', ' C ');

$arr 2 = ' abc ';
$t = Array_splice ($arr, 1, 0, $arr 2);

Print_r ($arr);

Console output:

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

A brief introduction to the Array_splice method, parameter one is an array of operations, parameter two is the index value of the operation element, parameter three is the length, parameter four is to replace the element.

The effect of this method is to delete the coherent element with 1 as the starting position, length 0 in $arr, and then fill it with $ARR2.

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

------------------------------------------------------------Gorgeous split Line Oo00o0ooo0oo ... ---------------------__________________________

The top array_splice is the pig's foot,

Array_push

Array_push--presses one or more cells into the end of the array (into the stack)

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

Array_push () will be array treated as a stack, and the incoming variable will be pressed into array the end. arraywill increase depending on the number of variables in the stack. The effect is the same as the following:

Inserting values anywhere in the PHP array

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.