Get a value based on a range between 2 numbers

Hello, so i have this data:

1-10=0%
11-50=1%
51-100=2%
101-250=3%
251-500=5%
501-1000=8%
1001-2000=11%
2001-5000=13%
5001-9999=15%

So if a number it’s between 1 and 10 i need to get a result back of 0% and so on .

Can someone help me with a code where i don’t need to use a lot of if’s i would like something simple, because i need to apply that on 3 different data like this one so that’s why i don’t want a huge code

I know it’s supposed to be some kind of array but i really don’t know how to even start with arrays.
Thank you very much for any help offered.

You can transform that into an array like

$ranges = [
 [1,10,0],
 [11,50,1],
 [51,100,2],
];

and then loop over it

foreach($ranges as $range){
 if($num >= $range[0] and $num <= $range[1]) $result = $range;
}

var_dump($result);
2 Likes

thank you, that solved my problem

Sponsor our Newsletter | Privacy Policy | Terms of Service