TrinityTuts Tips

Push array or value at specific position in php

Simple and easy way to add item at specific position of array in php

<?php
echo "<pre>";
$array = array(1,2,3,4,5,6);
array_splice($array, 4, 0, array('c'));
print_r($array);

Output:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => c
    [5] => 5
    [6] => 6
)