Evaluate the maximum value in a multi-dimensional array

Source: Internet
Author: User
Evaluate the maximum value array in a multi-dimensional array as follows:
Array
(
[0] => Array
(
[CampaignID] = & gt; 2304111
[ExistStatus] => 2
[CampaignName] => July Sales Promotion Center
[CampaignType] => targeted promotion plan
[AvgCommission] = & gt; 1.71%
[Exist] => 1
[ShopKeeperID] = & gt; 18791530
[Properties] => No
)

[1] => Array
(
[CampaignID] = & gt; 2979322
[CampaignName] => New Year promotional price
[CampaignType] => targeted promotion plan
[AvgCommission] = & gt; 4.90%
[Exist] =>
[ShopKeeperID] = & gt; 18791530
[Properties] => No
)

[2] => Array
(
[CampaignID] = & gt; 7275933
[CampaignName] => Thanks
[CampaignType] => targeted promotion plan
[AvgCommission] = & gt; 1.53%
[Exist] =>
[ShopKeeperID] = & gt; 18791530
[Properties] => No
)

)

Find out if AvgCommission is the maximum value, and add the CampaignID

Display the result as array (2979322, 4.9 );

My algorithm is too bad. I cannot understand it when I find many algorithms !!!


Reply to discussion (solution)

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);

You are the God of God

That is not necessarily the case. Such a combination of code is a regular expression, so you will be proficient in getting started.

For database queries
SELECT CampaignID, AvgCommission FROM tbl_name order by AvgCommission DESC
You must be familiar

In fact, they correspond one by one.

Thank you, God. I feel a little clear!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.