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: