如何删除数组元素然后重新索引数组? [英] How to Remove Array Element and Then Re-Index Array?
本文介绍了如何删除数组元素然后重新索引数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用数组时遇到了一些麻烦.我有一个要修改的数组,如下所示.我想通过索引删除它的元素(元素),然后重新索引数组.可能吗?
I have some troubles with an array. I have one array that I want to modify like below. I want to remove element (elements) of it by index and then re-index array. Is it possible?
$foo = array(
'whatever', // [0]
'foo', // [1]
'bar' // [2]
);
$foo2 = array(
'foo', // [0], before [1]
'bar' // [1], before [2]
);
推荐答案
unset($foo[0]); // remove item at index 0
$foo2 = array_values($foo); // 'reindex' array
这篇关于如何删除数组元素然后重新索引数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文