0

For some reason this "OR" statement is not working:

if($product->virtuemart_product_id != 153 || 170 || 171 || 195 || 208){
    //code here
}

It works when I only use one ID, but when I add many it doesn't work. Any ideas what could be wrong?

Aniket Sahrawat
  • 12,410
  • 3
  • 41
  • 67
MailBlade
  • 339
  • 4
  • 19

1 Answers1

2

You are doing it wrong. The correct way is:

if($product->virtuemart_product_id != 153 ||
   $product->virtuemart_product_id != 170 || 
   $product->virtuemart_product_id != 171 || 
   $product->virtuemart_product_id != 195 ||
   $product->virtuemart_product_id != 208)

It looks messy, but this is the way to do it.

A cleaner approach would be:

$arr = [153,170,171,195,208];
if( ! in_array($product->virtuemart_product_id, $arr) )

Read more about in_array()

Aniket Sahrawat
  • 12,410
  • 3
  • 41
  • 67