如何删除数组元素,然后重新指数阵? [英] How to Remove Array Element and Then Re-Index Array?
本文介绍了如何删除数组元素,然后重新指数阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些麻烦一个数组。我有我想修改类似下面一个阵列。我想通过索引删除元素(元素),然后重新索引数组。这可能吗?
$富=阵列( 什么',// [0]
'富',// [1]
'酒吧'// [2]);$ foo2的=阵列( '富',// [0],在[1]
'酒吧'// [1],在[2]);
解决方案
未设置($ foo的[0]); //在索引0删除项目
$ foo2的= array_values($ foo的); //重新索引阵
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屋!
查看全文