Problem:
I have a value that is set in $record, for instance 1.69. Then I have an array that contain different grades and values. I would like to compare $record against the highest value first to see if it is higher or equal to, if not go to the value below it, and so forth.
PHP code:
$record1 = '1.69';
$record2 = '2.90';
$record3 = '3.40';
$record4 = '3.80';
Array ($grades):
Array
(
[G] => 2.8
[VG] => 3.8
)
Scenario:
$record1 should be compared to the highest value in the array, this will return false. It will compare to the value below the highest value, which also will return false. If both return false then return the string 'U', otherwise return the key G or VG.
- Record 1 should produce U.
- Record 2 should produce G.
- Record 3 should produce G.
- Record 4 should produce VG.
Question:
I could do a lot of if-statements as a solution but I wonder if there is any clever way of doing this check in a better way?
$recordarray instead of independent variables?