数组是这样的:
Array
(
[0] => Array
(
[CampaignID] => 2304111
[ExistStatus] => 2
[CampaignName] => 7月促销中心
[CampaignType] => 定向推广计划
[AvgCommission] => 1.71 %
[Exist] => 1
[ShopKeeperID] => 18791530
[Properties] => 否
)
[1] => Array
(
[CampaignID] => 2979322
[CampaignName] => 新年 促销价
[CampaignType] => 定向推广计划
[AvgCommission] => 4.90 %
[Exist] =>
[ShopKeeperID] => 18791530
[Properties] => 否
)
[2] => Array
(
[CampaignID] => 7275933
[CampaignName] => 感恩
[CampaignType] => 定向推广计划
[AvgCommission] => 1.53 %
[Exist] =>
[ShopKeeperID] => 18791530
[Properties] => 否
)
)
找出AvgCommission为最大值的,同时还要带上CampaignID
让结果显示为array(2979322,4.9);
我算法太差了,找了好多都看不明白!!!
回复讨论(解决方案)
foreach($arr as $v) $r[] = $v['AvgCommission'];array_multisort($r, SORT_DESC, SORT_NUMERIC, $arr);$r = array($arr[0]['CampaignID'], $arr[0]['AvgCommission'] + 0);print_r($r);
你就是额的神
那也未必,这样的代码组合是定式,多接触就熟练了
如果是数据库查询,那么
SELECT CampaignID, AvgCommission FROM tbl_name ORDER BY AvgCommission DESC
你一定不陌生
其实他们是一一对应的
谢谢神,感觉明白了些了!
本文原创发布php中文网,转载请注明出处,感谢您的尊重!