PHP删除阵列和重新索引的第一指标 [英] PHP remove the first index of an array and re-index

查看:142
本文介绍了PHP删除阵列和重新索引的第一指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组一样
阵列

 
    [0] =>一个
    [2] =>乙
    [4] => C
    [6] => ð

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

 
    [0] =>乙
    [1] => C
    [2] => ð

哪个PHP函数,我需要使用?


更新

输入阵列

 阵列

    [0] =>排列
        (
            [0] =>一些不需要的文本
            [1] =>您crazyy
        )    [2] =>排列
        (
            [0] =>我的讲座敬爱的文字
            [1] =>您crazyy
        )    [10] =>排列
        (
            [0] =>我爱报价
            [1] =>您crazyy
        ))

和输出应该是像

 阵列

    [0] =>排列
        (
            [0] =>我的讲座敬爱的文字
            [1] =>您crazyy
        )    [1] =>排列
        (
            [0] =>我爱报价
            [1] =>您crazyy
        ))


解决方案

通过array_splice。

<一个href=\"http://www.php.net/manual/en/function.array-splice.php\">http://www.php.net/manual/en/function.array-splice.php


PHP>的print_r($输入);
排列

    [0] =>一个
    [2] =>乙
    [4] =>Ç
    [6]为=>

的PHP> array_splice($输入,0,1);
PHP>的print_r($输入);
排列

    [0] =>乙
    [1] =>Ç
    [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
        )

)

解决方案

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删除阵列和重新索引的第一指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆