移除密钥后将密钥移至0

时间:2015-02-04 01:59:01

标签: php arrays key associative-array

所以我有一个数组:

Array ( [Favorite-Search-Engines] => Array ( 
[0] => Google 
[1] => Yahoo 
[2] => Bing 
[3] => DuckDuckGo ) ) 

我希望用户能够删除密钥,但如果他们删除了一个密钥:

Array ( 
[Favorite-Search-Engines] => Array ( 
[0] => Google
[2] => Bing 
[3] => DuckDuckGo ) ) 

我希望按键向下移动到0:

阵列(     [Favorite-Search-Engines] =>阵列(     [0] =>谷歌     [1] =>兵     [2] => DuckDuckGo))

有没有办法做到这一点?  提前致谢

1 个答案:

答案 0 :(得分:2)

最简单的方法是使用:

$re_indexed_array = array_values($your_modified_array);