删除键后将键移向 0
Moving keys towards 0 after they are removed
所以我有一个数组:
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] => Google
[1] => Bing
[2] => DuckDuckGo ) )
有什么办法吗?
提前致谢
最简单的方法是使用:
$re_indexed_array = array_values($your_modified_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] => Google [1] => Bing [2] => DuckDuckGo ) )
有什么办法吗? 提前致谢
最简单的方法是使用:
$re_indexed_array = array_values($your_modified_array);