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

PHP remove the first index of an array and re-index(PHP删除数组的第一个索引并重新索引)
本文介绍了PHP删除数组的第一个索引并重新索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个像数组

<代码>([0] =>一个[2] =>乙[4] =>C[6] =>D)

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

<代码>([0] =>乙[1] =>C[2] =>D)

我需要使用哪个 PHP 函数?

<小时>

更新

输入数组是

数组([0] =>大批([0] =>一些不需要的文字[1] =>你疯了)[2] =>大批([0] =>我下面的文字[1] =>你疯了)[10] =>大批([0] =>我爱的名言[1] =>你疯了))

输出应该像

数组([0] =>大批([0] =>我下面的文字[1] =>你疯了)[1] =>大批([0] =>我爱的名言[1] =>你疯了))

解决方案

With array_splice.

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

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

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
        )

)

解决方案

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
)

这篇关于PHP删除数组的第一个索引并重新索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Subtract time in PHP(在 PHP 中减去时间)
Limit execution time of an function or command PHP(限制函数或命令 PHP 的执行时间)
How to sum N number of time (HH:MM Format)?(如何求和 N 次(HH:MM 格式)?)
How to get current time in milliseconds in PHP?(如何在 PHP 中以毫秒为单位获取当前时间?)
How to check if time is between two times in PHP(如何检查时间是否在 PHP 中的两次之间)
Convert number of minutes into hours amp; minutes using PHP(将分钟数转换为小时数分钟使用 PHP)