Re: [PHP] Is there limitation for switch case: argument's value?

2009-08-24 Thread Keith
Oh I see. I missed out one thing too. There is no need to put the same code under both case 7 & 6 separately, but just under case 6 will do. This is simpler in fact! Thanks Tedd and Torben! I'll fix to this style from now onwards. "tedd" wrote in message news:p06240800c6b84328c...@[192.168.1

Re: [PHP] Is there limitation for switch case: argument's value?

2009-08-24 Thread tedd
At 9:44 PM -0700 8/22/09, Lars Torben Wilson wrote: Hi Keith, Glad it works! I'm not sure how inverting the case statement helps you minimize the code in each case. As both I and Adam showed, you can do the same thing more efficiently (and IMHO much more readably) like this: switch ($sum) {

Re: [PHP] Is there limitation for switch case: argument's value?

2009-08-22 Thread Lars Torben Wilson
Aargh. Slipped on the trigger there--premature Send. See below for what I meant to send: 2009/8/22 Lars Torben Wilson : > 2009/8/22 Keith : >> Thanks! Torben. >> I got the point now and it works! :-) >> I'm doing this because the statements of each cases is quite long, and I >> wish to have minimu

Re: [PHP] Is there limitation for switch case: argument's value?

2009-08-22 Thread Lars Torben Wilson
2009/8/22 Keith : > Thanks! Torben. > I got the point now and it works! :-) > I'm doing this because the statements of each cases is quite long, and I > wish to have minimum coding without repetition. Hi Keith, Glad it works! I'm not sure how inverting the case statement helps you minimize the co

Re: [PHP] Is there limitation for switch case: argument's value?

2009-08-22 Thread Keith
August 20, 2009 11:20 PM To: Keith Cc: php-general@lists.php.net Subject: Re: [PHP] Is there limitation for switch case: argument's value? I've never understood why people use switch statements like this as in reality you are using it more like an if/else block, but anyway. The reason w

Re: [PHP] Is there limitation for switch case: argument's value?

2009-08-22 Thread Keith
Thanks! Adam. It works now! Actually I thought that switch block is compatible with if/elseif/else block but more efficient if the cases is >3. Because I like to have short coding without repetition, so I group the similar cases together. Thanks for your explanation! I know where is my mistake a

Re: [PHP] Is there limitation for switch case: argument's value?

2009-08-22 Thread Keith
Thanks! Torben. I got the point now and it works! :-) I'm doing this because the statements of each cases is quite long, and I wish to have minimum coding without repetition. "Lars Torben Wilson" wrote in message news:36d4833b0908202323p3c858b5fn6a1d6775aa7f8...@mail.gmail.com... 2009/8/20

RE: [PHP] Is there limitation for switch case: argument's value?

2009-08-21 Thread Daevid Vincent
l your base are belong to Adam. > -Original Message- > From: Adam Randall [mailto:randa...@gmail.com] > Sent: Thursday, August 20, 2009 11:20 PM > To: Keith > Cc: php-general@lists.php.net > Subject: Re: [PHP] Is there limitation for switch case: > argument's valu

Re: [PHP] Is there limitation for switch case: argument's value?

2009-08-20 Thread Lars Torben Wilson
2009/8/20 Keith : > Hi, > I encounter a funny limitation here with switch case as below: > The value for $sum is worked as expected for 1 to 8, but not for 0. > When the $sum=0, the first case will be return, which is "sum=8". > Is there any limitation / rules for switch case? Thanks for advice! >

Re: [PHP] Is there limitation for switch case: argument's value?

2009-08-20 Thread Adam Randall
I've never understood why people use switch statements like this as in reality you are using it more like an if/else block, but anyway. The reason why your code is not working is that you are passing into the switch the value of 0, or false, which means that when any of those $sum == N conditional

[PHP] Is there limitation for switch case: argument's value?

2009-08-20 Thread Keith
Hi, I encounter a funny limitation here with switch case as below: The value for $sum is worked as expected for 1 to 8, but not for 0. When the $sum=0, the first case will be return, which is "sum=8". Is there any limitation / rules for switch case? Thanks for advice! Keith $sum=0; switch($sum)