lundi 17 juillet 2017

Automating IF statements

I am working on page where are multiple variants of same product. I'm using if statements to check if there is some change to show. However, as you can see I am repeating pretty much the same thing with if statements. How can I automate multiple if statements to a one?

Something like this: if($s->??? !=0 ) { product->??? = $s->???;} ?

     while ($s = $subProduct->fetch(PDO::FETCH_OBJ)){

   $product->variant = $s->variant;

   if ($s->price != 0 ) {
        $product->price = $s->price;
       }
   if ($s->battery != 0 ) {
        $product->battery = $s->battery;
      }
   if ($s->topspeed != 0 ) {
        $product->topspeed = $s->topspeed;
       }
     if ($s->range != 0 ) {
        $product->range = $s->range;
        }
      }
    }

Aucun commentaire:

Enregistrer un commentaire