沃梦达 / 编程问答 / php问题 / 正文

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删除数组的第一个索引并重新索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHP删除数组的第一个索引并重新索引

基础教程推荐