gpt4 book ai didi

php - uasort 问题 - 首先输出最大值

转载 作者:行者123 更新时间:2023-11-29 06:15:46 26 4
gpt4 key购买 nike

如果一个对象中有 2 列

A -> 值为 10 8 6 4

B -> 值为 9 7 5 3

我想将 B 合并到 A 中,其中 9 低于 10,7 低于 8 等等。

uasort($TopConsumers,array('Utilities','orderconsumers'));
public static function orderConsumers($TopConsumers)
{
$a = $TopConsumers->outTotal;
$b = $TopConsumers->inTotal;
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : +1;
}

为什么这不起作用?

最佳答案

您需要先合并数组,然后再排序。

$merged = array_merge($TopConsumers->outTotal, $TopConsumers->inTotal);
sort($merged);

关于php - uasort 问题 - 首先输出最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6652862/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com