【问题标题】:Unset an array key, and restore the sorting [duplicate]取消设置数组键,并恢复排序[重复]
【发布时间】:2012-12-18 07:30:06
【问题描述】:

可能重复:
PHP remove the first index of an array and re-index
How to Remove Array Element and Then Re-Index Array?

$arr = array(1, 2, 3);

unset($arr[0]);

print_r($arr);

//Array ( [1] => 2 [2] => 3 ) 

调用的函数是什么,所以输出应该是:

//Array ( [0] => 2 [1] => 3 ) 

【问题讨论】:

标签: php


【解决方案1】:

您想使用array_values 创建一个新数组:

$arr = array(1, 2, 3);
unset($arr[0]);
$arr = array_values($arr);

print_r($arr);
//Array ( [0] => 2 [1] => 3 ) 

【讨论】:

    猜你喜欢
    • 2011-08-22
    • 1970-01-01
    • 2015-02-01
    • 2013-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多