I have 3 dropdowns selects
(each drop-down has values from 0 to 25):
<select class="form-select" id="select1" name="select1">
<option selected value="0">label...</option>
<option value="5">label...</option>
<option value="10">label...</option>
<option value="15">label...</option>
<option value="20">label...</option>
<option value="25">label...</option>
</select>
<select class="form-select" id="select2" name="select2">
<option selected value="0">label...</option>
<option value="5">label...</option>
<option value="10">label...</option>
<option value="15">label...</option>
<option value="20">label...</option>
<option value="25">label...</option>
</select>
<select class="form-select" id="select3" name="select3">
<option selected value="0">label...</option>
<option value="5">label...</option>
<option value="10">label...</option>
<option value="15">label...</option>
<option value="20">label...</option>
<option value="25">label...</option>
</select>
I’m trying to calculate the total score for all 3 dropdowns using _GET:
//get select values
$select1= $_GET['select1'];
$select2= $_GET['select2'];
$select3= $_GET['select3'];
$totalValues = array($select1, $select2, $select2);
$totalScore = array_sum($totalValues);
But also use conditions as follows:
//if any values are between 5-9
if ($totalScore <= 15)
{
//this is the condition I'm stuck on - checking for min/max values in the array
if ($totalValues >= 5 && $totalValues <=9)
{
$rating = 5;
}
}
//and the same logic below...
- if any values are between 10-14
- if any values are between 15-19
- if any values are between 20-25
What is the best approach to use?
I pased all 3 values into an array then am trying to use in_array() to check the above conditions.
Hope that makes sense.
2
Answers
Think I've solved it with this logic:
You can set up your logic like below to support several cases:
If any value is between 5-9
if any values are between 10-14
if any values are between 15-19
if any values are between 20-25