My application generates a random integer between 0 and 1000.
I have 5 ranges: 0-50
, 51-250
, 251-500
, 501-700
, 701-1000
. (Note that the range sizes are not equal.)
I will call these ranges: "0","50","250","500","700", respectively (will store those names in my database).
I know that i could do the following:
if ($number > 700 && $number <=1000)
$num_range='700';
else if...
... and so on.
But is there a more efficient way of doing it?
Thanks a lot in advance. Regards
Utilize elseif
efficiently:
if($number <= 50)
$num_range='0';
elseif($number <= 250)
$num_range='50';
elseif($number <= 500)
$num_range='250';
elseif($number <= 700)
$num_range='500';
elseif($number <= 1000)
$num_range='700';
...
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