I have the following array:
$groupA= array(1,10);
$groupB = array(11,20);
$groupC = array(21,30);
The user has the possibility to enter any numeric value into a text-box, for example "5" now I need to display the user in which group that number is. I've done this before this way:
And then do a switch case like this:
switch ($input){
case ($input>= $groupA[0] && $input<= $groupA[1]):
echo "You are in Group A.";
break;
case ($input>= $groupB[0] && $input<= $groupB[1]):
echo "You are in Group B.";
break;
However, this seems not feasable since we have got many many groups (likely over 200) and using this many switch-cases is unefficient.
Any ideas on how to solve this more elegantly?
array(1,10,11,20,21,30)and do a binary search. The found key(s) will tell you which group it belongs to.