對於前有此數組:關聯數組 - 改變位置
[food] => Array (
[fruits] => apple
[vegetables] => garlic
[nuts] => cashew
[meat] => beaf
)
我需要改變一個特定的鍵值組合的位置。
比方說,我需要[水果] =>蘋果移動到第三的位置
[food] => Array (
[vegetables] => garlic
[nuts] => cashew
[fruits] => apple
[meat] => beaf
)
我不是在談論的鍵或值排序。 我需要將鍵值的位置更改爲非常嚴格的新位置。
喜歡的東西:
change_pos($my_arr, $key_to_move, $new_index);
=>
change_pos($my_arr, "fruits", 3);
這可能嗎?
是否適用於無數字索引?你可以使用http://phpfiddle.org – 2013-03-01 22:05:08
提供演示示例這不能正常工作,不要移動其他元素的索引 – Sam 2013-03-01 22:07:39
編輯,努力工作,但完成。 – MIIB 2013-03-01 22:34:51