I have the following variables:
$points_maxbet = 0;
$points_netbet = 0;
$points_888 = 0;
$points_sportingbet = 0;
$points_betano = 0;
$points_unibet = 0;
$points_betfair = 0;
During the execution of the script their values get incremented by different values.
Example:
if ((mysqli_real_escape_string($con, $_POST['question_01'])) == 'A')
{
$points_maxbet += 5;
$points_netbet += 5;
$points_888 += 5;
$points_sportingbet += 5;
$points_betano += 5;
$points_unibet += 5;
$points_betfair += 5;
}
After they pass trough all of the increments I want to display just 3 out of those 7 variables (based on their highest values) and display some HTML for each of them.
I tried something but it would only give me the highest value variable, not the following 2 as well.
Looked for a solution on SO and Google but couldn't find any.
Let me know if I need to provide more details.
I would say, put them in an array at the end, sort them and pick off the top 3 elements. Sort of like the following:
<?php
$array = array(
'maxbet' => $points_maxbet,
'netbet' => $points_netbet,
'eighteighteight' => $points_eighteighteight,
'sportingbet' => $points_sportingbet,
'betano' => $points_betano,
'unibet' => $points_unibet,
'betfair' => $points_betfair);
asort($array);
$top3 = array_slice($array, -3);
?>
Using this in html could be as simple as something like this (code not tested yet):
<ol>
<?php foreach($top3 as $key => $value): ?>
<li><?php echo $key; ?> - <?php echo $value; ?></li>
<?php endforeach; ?>
</ol>
Put them into an array and use asort
to order the array lowest->highest then pop
off the last 3
$arr = [$maxbet, $netbet, $eighteighteight, $sportingbet, $betano, $unibet, $betfair];
asort($arr);
$first = array_pop($arr);
$second = array_pop($arr);
$third = array_pop($arr);