Insert value anywhere in php array
Oct 19, 2016 am 10:19 AMarray_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. The first parameter is the array being operated on, the second parameter is the index value of the operating element, the third parameter is the length, and the fourth parameter is the element to be replaced.
The effect of this method is to delete the consecutive elements with 1 as the starting position and length 0 in $arr, and then fill them with $arr2.
tips:If the length is 0, the effect is equivalent to inserting the specified element at the specified index value.
------------------------------------------------- -----------Gorgeous dividing lineoo00o0ooo0oo. . . --------------------------______________________________
The array_splice above is just pig’s feet,
array_push
array_push -- Push one or more cells to the end of the array (push)
Instructions
int array_push ( array &array, mixed var [, mixed ...] )array_push() treats array as a stack and pushes the passed variables into the end of array. The length of array will be increased according to the number of variables pushed onto the stack. The same effect as the following:

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)