055 - array_splice (edit in same array with different value and array)
a =
Array
(
    [0] => blue
    [1] => yellow
    [2] => brown
)
b =
Array
(
    [0] => green
    [1] => blue
    [2] => yellow
)
c =
Array
(
    [0] => green
    [1] => blue
)
d =
Array
(
    [0] => brown
)
e =
Array
(
    [0] => red
)
f =
Array
(
    [0] => red
    [1] => green
)
g =
Array
(
    [0] => blue
    [1] => yellow
)
h =
Array
(
    [0] => blue
    [1] => yellow
    [2] => brown
)
i =
Array
(
)
j =
Array
(
)
k =
Array
(
)
<?php // 055 - array_splice (edit in same array with different value and array) (array,start,length,array 2) echo "</br><span class='myheading'><del>055 - array_splice (edit in same array with different value and array)</del></span></br>"; // https://www.youtube.com/watch?v=wWFmzR6jNkw&list=PL0b6OzIxLPbyrzCMJOFzLnf_-_5E_dkzs&index=45 $color_a_055 =["red","green","blue","yellow","brown"]; echo "a = <pre>"; print_r (array_splice($color_a_055, 2 )); /* form index 2 , delete all at end*/ echo "</pre>"; $color_b_055 =["red","green","blue","yellow","brown"]; echo "b = <pre>"; print_r (array_splice($color_b_055, 1, -1)); // go reverse direction excluding -1 index ( like 1, 0, -1) echo "</pre>"; $color_c_055 =["red","green","blue","yellow","brown"]; echo "c = <pre>"; print_r (array_splice($color_c_055, 1, -2)); echo "</pre>"; $color_d_055 =["red","green","blue","yellow","brown"]; echo "d = <pre>"; print_r (array_splice($color_d_055, -1)); /* exclude -1 position and delete all-------- */ echo "</pre>"; $color_e_055 =["red","green","blue","yellow","brown"]; echo "e = <pre>"; print_r (array_splice($color_e_055, 0, 1)); /* -------Remove the first element of $color------- */ echo "</pre>"; $color_f_055 =["red","green","blue","yellow","brown"]; $fruit_a_055 = ["Orange", "Apple"]; echo "f =<pre>"; print_r (array_splice($color_f_055, 0 , 2, $fruit_a_055)); /* -----------Remove First Two elements and add new elements in $color ------------- */ echo "</pre>"; $color_g_055 =["red","green","blue","yellow","brown"]; $fruit_b_055 = ["Orange", "Apple"]; echo "g = <pre>"; print_r (array_splice($color_g_055, 2 , 2, $fruit_b_055)); /* -----------Replace Third and fourth element in $color ------------- */ echo "</pre>"; $color_h_055 =["red","green","blue","yellow","brown"]; $fruit_c_055 = ["Orange", "Apple"]; echo "h =<pre>"; print_r (array_splice($color_h_055, 2, count($color_h_055), $fruit_c_055));/* -----------use count method in $color ------------- */ echo "</pre>"; $color_i_055 =["red","green","blue","yellow","brown"]; $fruit_d_055 = ["Orange", "Apple"]; echo "i =<pre>"; print_r (array_splice($color_i_055, 2, 0, $fruit_d_055));/* -----------add new elements in $color with count method ------------- */ echo "</pre>"; $color_j_055 =["red","green","blue","yellow","brown"]; $fruit_e_055 = ["Orange", "Apple"]; echo "j =<pre>"; print_r (array_splice($color_j_055, 0, 0, $fruit_e_055));/* -----------add new elements in begining of $color with count method ------------- */ echo "</pre>"; $color_k_055 =["red","green","blue","yellow","brown"]; $fruit_f_055 = ["Orange", "Apple"]; echo "k =<pre>"; print_r (array_splice($color_k_055,count($color_k_055),0, $fruit_f_055));/* -----------add new elements in the end of $color with count method ------------- */ echo "</pre>"; ?>