1
现在我有两个阵列 - $totaltimeplayed
和$gameslist
其中$totaltimeplayed
中的每个值指的是在$gameslist
中玩对应游戏的时间。我想排列在$totaltimeplayed
中玩游戏的时间,然后根据$gameslist
对游戏进行排序。如何对一个数组排序并使用键顺序对PHP中的第二个数组进行排序?
我迄今为止代码:
arsort($totaltimeplayed);
$key_order = array_keys($totaltimeplayed);
$sort_games = array_combine($key_order, $gameslist);
ksort($sort_games);
当我使用print_r()
,似乎$ gameslist的排序是任意的,并没有特定的顺序。
什么问题?
主要ID 10吨的错误。 PHP.net手册使它看起来像arsort()自动按降序排序。谢谢! – user3642365
它确实,但我忽略了你的问题,编辑过。 – AbraCadaver