I wrote a simple script with many conditions:
$item =12;
if($item < 5)
{
//display icon buyer
}
elseif ($item < 10)
{
//display icon buyer
}
elseif ($item < 15)
{
//display icon good buyer
}
elseif ($item < 20)
{
//display icon top buyer
}
// etc....
It’s a long multi condition and I know is very bad.
How I could optimize the code?
Note. switch is not possible because I’m using the operators < and >, etc.
Better than a bunch of conditionals is to look for a pattern that allows to just calculate it.
In your case it looks like that are steps by 5 – so appropriate for division.
Or map it:
Which allows more flexible steps (as you have it in your data in question).