Warm tip: This article is reproduced from serverfault.com, please click

php-如何删除数组元素,然后重新索引数组?

(php - How to Remove Array Element and Then Re-Index Array?)

发布于 2011-03-07 09:04:20

我在数组上遇到了麻烦。我有一个要修改的数组,如下所示。我想通过索引删除它的元素(元素),然后重新索引数组。是否可以?

$foo = array(

    'whatever', // [0]
    'foo', // [1]
    'bar' // [2]

);

$foo2 = array(

    'foo', // [0], before [1]
    'bar' // [1], before [2]

);
Questioner
daGrevis
Viewed
0
xzyfer 2011-03-07 17:06:19
unset($foo[0]); // remove item at index 0
$foo2 = array_values($foo); // 'reindex' array