remove first array from an array

0

I have the following array and would like to always remove the first array, how can I do this? obs: there is a possibility that the first array does not always have index 0.

Array
    (
        [0] => Array
            (
                [0] => number
            )

        [1] => Array
            (
                [0] => 101010100
            )
        [2] => Array
            (
                [0] => 30303030
            )
)
    
asked by anonymous 16.05.2017 / 18:11

3 answers

3

Use array_shift :

$arr  = [['number'], [101010100], [30303030]];

array_shift($arr);

print_r($arr);

Will return:

Array
(
    [0] => Array
        (
            [0] => 101010100
        )

    [1] => Array
        (
            [0] => 30303030
        )

)

Example on ideone

    
16.05.2017 / 18:21
2
    <?php
            $cars = array
                 (
                 array("Volvo",22,18),
                 array("BMW",15,13),
                 array("Saab",5,2),
                 array("Land Rover",17,15)
                 );
            array_shift($cars); //Retira o primeiro elemento do array
    ?>
    
16.05.2017 / 18:19
2

You can use the array_splice function and remove a portion of the array.

$novoArray = array_splice($array, 1);

Remove to the first position and adjust the indexes.

    
16.05.2017 / 18:22