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