如何在PHP中对一个数组进行排序并使用键顺序对第二个数组进行排序?
现在我有两个数组-如何在PHP中对一个数组进行排序并使用键顺序对第二个数组进行排序?,php,arrays,sorting,Php,Arrays,Sorting,现在我有两个数组-$totaltimeplayed和$gameslist,其中$totaltimeplayed中的每个值都表示在$gameslist中玩相应游戏所花费的时间。我想在$totaltimeplayed中对玩游戏花费的时间进行排序,然后在$gameslist中对游戏进行相应的排序 到目前为止,我的代码是: arsort($totaltimeplayed); $key_order = array_keys($totaltimeplayed); $sort_games = array_co
$totaltimeplayed
和$gameslist
,其中$totaltimeplayed
中的每个值都表示在$gameslist
中玩相应游戏所花费的时间。我想在$totaltimeplayed
中对玩游戏花费的时间进行排序,然后在$gameslist
中对游戏进行相应的排序
到目前为止,我的代码是:
arsort($totaltimeplayed);
$key_order = array_keys($totaltimeplayed);
$sort_games = array_combine($key_order, $gameslist);
ksort($sort_games);
当我使用print\r()
时,$gameslist的排序似乎是任意的,没有特定的顺序
有什么问题吗?我喜欢:
主要ID 10 T错误。PHP.net手册使它看起来像是自动按降序排序的arsort()。非常感谢。
array_multisort($totaltimeplayed, SORT_DESC, $gameslist);