As shown below:
$ary = array( array('t'=>1,'y'=>2), array('t'=>2,'y'=>9) ); $t = array_splice( $ary, 1,0,array(array('t'=>3,'y'=>10)) ); print_r($ary);
Console output:
$ary = array( array('t'=>1,'y'=>2), array('t'=>3,'y'=>10), array('t'=>2,'y'=>9) );
Let me briefly introduce the array_splice method. Parameter one is the array being operated, parameter two is the index value of the operation element, parameter three is the length, and parameter four is the element to be replaced. The effect of this method is to delete the coherent elements in the parameter one array with parameter two as the starting position length parameter three, and then fill it with parameter four.
If the length is 0, the effect is equivalent to inserting the specified element at the specified index value.
If the length is 1, the effect is equivalent to removing the element with the index value.
$ary = array( array('t'=>1,'y'=>2), );
Delete specific elements in the array
$arr1 = array(1,3, 5,7,8); $key = array_search(3, $arr1); if ($key !== false){ array_splice($arr1, $key, 1); } var_dump($arr1);
Output: array(1, 5, 7, 8);
array_slice(array,start,length,preserve)
Start from the start element of the array and return the remaining elements in the array
$a=array("red","green","blue","yellow","brown"); print_r(array_slice($a,2));
Output array("blue","yellow","brown")
array_push
array_push -- Push one or more cells into the end of an array (to stack)
illustrate
int array_push ( array &array, mixed var [, mixed ...] )
array_push() treats array as a stack and pushes incoming variables to the end of array. The length of array will increase according to the number of stacked variables.
The above article inserting elements at any location in the array and deleting specific elements is the entire content I share with you. I hope you can give you a reference and I hope you can support me more.