Ask for help in a sudden.

Source: Internet
Author: User
Ask for help ...
The following table is taken from the database. You should get more.
ID a B
0 10 2
1 30 5
2 50 4

Ask for the highest number from a, and then use this number plus the other number of B
Example: 50+2+5=57

What should I do if I use only one array?
Or is there a better solution?
(Those numbers seem to be all strings)
------Solution--------------------
Just find it in the database.

Select Max (Concat (A, '-', b)) as A,sum (b) as B from test

Results:
A b
50-4 11
50-4+11=57
------Solution--------------------
$a = Array (10, 30, 50);
$b = Array (2, 5, 4);
$max = max ($a);
$sum = 0;
foreach ($a as $i = $v)
if ($v < $max) $sum + = $b [$i];
echo $max + $sum;

------Solution--------------------

$arr = Array (
Array (10, 2),
Array (30, 5),
Array (50, 4)
);

$index = 0;
$max = 0;
For ($i =0, $len =count ($arr), $i < $len; $i + +) {
if ($arr [$i][0]> $max) {
$max = $arr [$i][0];
$index = $i;
}
}

$total = $max;
For ($i =0, $len =count ($arr), $i < $len; $i + +) {
if ($i = = $index) {
Continue
}
$total + = $arr [$i][1];
}

Echo $total; 57
  • 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.