mardi 27 septembre 2016

Cascade of IF statements - best solution

I have this situation:

Example

The User can choose between 3 products, A, B or C, like showed in the image. After the user clicks one of the products, he is redirected to a register form where he must include some data, including x and y. If the selected product and the value of x and y are not right, an error is launched. If the entered data is correct, then some other actions are done. I've tried to implement this control, but I'm not sure this is the best solution.

    if ($product==("A") && x < 10 && y <= 2)
{
     //some action                       

}

else if ($product ==("B") && x < 50 && y <= 10 && y >2)
{
      //some action                  
}

else if ($product ==("C") && x < 250 && y <=50)
{
       //some action                 
}

Aucun commentaire:

Enregistrer un commentaire