Originally we have an array as follow
$fruits = array( '0' => 'apple', '1' => 'banana', '2' => 'pear', );
So i want to insert “melon” into the 2nd position which is after “apple”. We can do it by array_splice().
array_splice($fruits , 1, 0, 'melon');
Now we have
$fruits = array( '0' => 'apple', '1' => 'melon', '2' => 'banana', '3' => 'pear', );
Done =)
Reference:
Filed under: PHP Tagged: PHP