jeudi 16 juillet 2020

Use appropriate formula by range in PHP

I have to count prices using different formula using price range as a float.

For example:
if price is lower than 100 use first option;
if price is between 100-300 use the second option, etc.

Here is some PHP code I am try to use:

if ($price <=100)
{
    $pricecount=(float)$price*1.25+25;
}
if ($price >100 && $price <=300)
{
    $pricecount=$price*1.25+20;
}
if ($price >200 && $price <=600)
{
    $pricecount=$price*1.2+20;
}
if ($price >600 && $price <=1000)
{
    $pricecount=$price*1.2;
}
else
{
    $pricecount=$price*1.15;
}                                

Now only second formula is used. How to do it appropriatly?

Aucun commentaire:

Enregistrer un commentaire