如果在我道歉之前已经回答了这个问题(我还没有发现)。我有一个游戏池网站,希望按分数(pts)进行排序。在下面的示例中,我希望“团队B”在第一位,因为他们的得分要高于 12 ,而他们的得分要高于A组的 22 。尽管此页面(How to sort an array of associative arrays by value of a given key in PHP?)上的解决方案与我一直在寻找的解决方案非常相似,但我无法使其正常运行。
Array
(
[0] => Team Object
(
[id] => 5
[name] => Team A
[games_played] => 13
[wins] => 6
[losses] => 7
[ot_losses] => 0
[pts] => 12
[goals_for] => 7.5
[goals_against] => 22
[streak] => 6-7
)
[1] => Team Object
(
[id] => 2
[name] => Team B
[games_played] => 13
[wins] => 11
[losses] => 2
[ot_losses] => 0
[pts] => 22
[goals_for] => 51
[goals_against] => 19
[streak] => 11-2
)
我怀疑我在以下方面是正确的道路,但缺少某些东西...
$new_array = array();
foreach ($array_objects as $key => $row)
{
$new_array[$key] = $row['pts'];
}
array_multisort($price, SORT_DESC, $array_objects);