PHP remove the first index of an array and re-index PHP remove the first index of an array and re-index php php

PHP remove the first index of an array and re-index


With array_splice.

http://www.php.net/manual/en/function.array-splice.php

php > print_r($input);Array(    [0] => A    [2] => B    [4] => C    [6] => D)php > array_splice($input, 0, 1);php > print_r($input);Array(    [0] => B    [1] => C    [2] => D)


we can do it with array_shift() which will remove the 1st index of array and after that use array_values() which will re-index the array values as i did not get from the @User123's answer, try below one:

<?php    $array = array(                0 => "A",                2 => "B",                4 => "C",                6 => "D"            );    array_shift($array);    $array = array_values($array);    echo "<pre>";    print_r($array);

Output: check the output here https://eval.in/837709

Array    (        [0] => B        [1] => C        [2] => D    )

Same for your Updated Input array

<?php    $array = array(                    0 => array(                            0 => "Some Unwanted text",                            1 => "You crazyy"                        ),                    2 => array(                            0 => "My belowed text",                            1 => "You crazyy"                        ),                    10 => array(                            0 => "My loved quote",                            1 => "You crazyy"                        )                );    array_shift($array);    $array = array_values($array);    echo "<pre>";    print_r($array);

Output: check the output here https://eval.in/837711

Array(    [0] => Array        (            [0] => My belowed text            [1] => You crazyy        )    [1] => Array        (            [0] => My loved quote            [1] => You crazyy        ))