Question concerning SWITCH and Comparisons

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If my understanding of SWITCH is correct, it stops at the first case that
matches the result, correct?

So then.. If I have a switch as such;

switch($qty){

case ($qty < 1600): //$qty is less than 1600
  do something
break;

case ($qty < 2400): //$qty is less than 2400
  do something
break;

case ($qty >= 2400); //$qty is greater than or equal to 2400
  do something
break;

default:
 do something
break;
}

Then assuming $qty = 800, it should stop at the first case? right?

a $qty of 1601 should stop at the second case?

and a qty of greater than or equal to 2400 should stop at the last case?

Am I correct with my switch statement then?

My desired result is;

If quantity is less than 1600 set price = whatever;
or if quantity is equal to 1600 and less than 2400 set price = whatever,
or finally if quantity is equal to or greater than 2400 set price =
whatever.

I'm having difficulties for whatever reason to come up with a proper
comparison
for the switch to work as described.  Can someone help me iron out this
small problem?


Much thanks for the help,

Tony D.

[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux