Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

please correct this if statement's syntax


211655

Recommended Posts

Posted

whats wrong here. i want to find out that if any of them is greater than 10

if (($cartProducts[0]['weight']) > 10 II ($cartProducts[1]['weight']) > 10 II ($cartProducts[2]['weight']) > 10 ) {

 

i need:

if weight[0] > 10 or weight[1] > 10 or.....

Posted

Maybe

if (($cartProducts[0]['weight'] > 10 ) | ($cartProducts[1]['weight'] > 10 ) ?| ($cartProducts[2]['weight'] > 10 )) {

?

Antonios

 

olympicslogo_en.gif

Posted

I've always used double vertical bars to represent 'or' ( || ), is there a difference between the single one and the double one? I never even though to try if the single one works.

Posted

It's actually the bar above the "backslash" ( \ ) on your keyboard.

 

Also:

 

if weight[0] > 10 or weight[1] > 10 or.....

 

how many products are you checking? are you looking to evaluate the weight of every product in your cart? if you are, writing a bunch of "or" operators won't do your script much justice.

 

It would be more practical to do a while/for/foreach loop around everything that evaluates a variable like $i to the size of the $cartProducts array, then your if statement would look something like this:

 

if ($cartProducts[$i]['weight'] >10)
{
....
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...