OK. So I have a bunch of variables containing a number from 1-4. Like:
$score1 = 1;
$score2 = 3;
$score3 = 2;
$score4 = 1;
$score5 = 4;
$score6 = 2;
And then I use
min($score1, $score2, $score3, $score, $score5, $score6);
and the result is that 1 is the lowest score.
Is there a way for me to find out which variables returned the lowest score?
In this particular example this would then tell me that $score1 and $score4 returned an integer equal to the lowest integer.
Any suggestions much appreciated.
make array and find keys with values equal to min value
$a = array($score1, $score2, $score3, $score4, $score5, $score6);
print_r(array_keys($a, min($a))); // [0,3]
I would first and foremost recommend using an array rather than sooo many variables. And in an array we have something like array[0], array[1], and so on.
And then once you have all the scores in an array you can use built in methods like get the index of an array or sort an array values or get the min value etc.
The best way to find out the lowest score would be by first sorting in ascending and pulling the first array index value. But there are many approaches in getting the min value and the location of it in an array.
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With