Mithun Sreedharan Mithun Sreedharan - 3 years ago 110
PHP Question

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

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
)

)

Answer Source

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
)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download