PHP 删除数组的第一个索引并重新索引

2022-08-30 18:46:10

我有一个像 Array 这样的数组

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

我想删除第一个元素,然后重新索引数组以获取输出

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

我需要使用哪个PHP函数?


更新

输入数组为

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
(
    [0] => Array
        (
            [0] => My belowed text
            [1] => You crazyy
        )

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

)

答案 1

您可以使用

array_shift($array)

array_shift文档


答案 2

与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
)