views:

215

answers:

2

I have an array like Array

(
    [0] => A
    [2] => B
    [4] => C
    [6] => D
)

I want to remove the first element and then re-index array to get the output

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

Which PHP function i need to use?


Update

Input array is

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
        )

)

And the output should be like

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

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

)
+10  A: 

you can used

array_shift($array).

go through: http://in3.php.net/manual/en/function.array-shift.php

Deepali
i dont think array_shift would reindex the array
lemon
you try it>>>>>
Deepali
@lemon: the manual says otherwise: `All numerical array keys will be modified to start counting from zero`
intuited
Please see the updated question, array_shift trick is not working if the values of passing array is again an array
Mithun P
Melmacian's answer with array_splice seems to be working, any one tried that?
Mithun P
@intuited @Deepali my bad!
lemon
For me (PHP 5.3.2, Ubuntu), it gives the output requested in the updated question.
Matthew Flaschen
+2  A: 

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
)

Epeli
Need to omit the third parameter array_splice($input, 0)
Mithun P