By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,532 Members | 1,514 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,532 IT Pros & Developers. It's quick & easy.

Switch statement

P: n/a
<?php

switch ($var) {

case ("02100" || "02700" || "02500"):

/*
rest of code......
*/

break;

}

?>

Does this work???? (i mean the || statement(s) in combination with a switch
statement?

Marcel
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Marcel wrote:
<?php

switch ($var) {

case ("02100" || "02700" || "02500"):

/*
rest of code......
*/

break;

}

?>

Does this work???? (i mean the || statement(s) in combination with a switch
statement?


I don't know if your method works, but traditionally you made use of
switch()'s fall through:

switch($var) {
case "02100":
case "02700":
case "02500":
/* code */
break;
}

HTH,

Luke

Jul 17 '05 #2

P: n/a
Luke Ross wrote:
Marcel wrote:
<?php

switch ($var) {

case ("02100" || "02700" || "02500"):

/*
rest of code......
*/

break;

}

?>

Does this work???? (i mean the || statement(s) in combination with a
switch
statement?

I don't know if your method works, but traditionally you made use of
switch()'s fall through:

switch($var) {
case "02100":
case "02700":
case "02500":
/* code */
break;
}

HTH,

Luke


Also try to use single quotes instead of double, otherwise the PHP
parser has to parse the contents twice.

switch($var) {
case '02100':
case '02700':
case '02500':
/* code */
break;
}

Grant.
Jul 17 '05 #3

P: n/a

"Luke Ross" <lu******@sys3175.co.uk> schreef in bericht
news:vp************@corp.supernews.com...
Marcel wrote:
<?php

switch ($var) {

case ("02100" || "02700" || "02500"):

/*
rest of code......
*/

break;

}

?>

Does this work???? (i mean the || statement(s) in combination with a switch statement?


I don't know if your method works, but traditionally you made use of
switch()'s fall through:

switch($var) {
case "02100":
case "02700":
case "02500":
/* code */
break;
}

HTH,

Luke


Sorry for being so lazy...... i figured it out myself....

<?php

$var = "02700";

switch ($var) {

case ("02100" || "02700" || "02500"):

echo "<HR>Yes this works ok!!! (\$var = $var)<HR>";

break;

}

?>

So, it works!!!!

Thanks anyway!!!!

Marcel
Jul 17 '05 #4

P: n/a
Marcel wrote:
"Luke Ross" <lu******@sys3175.co.uk> schreef in bericht
news:vp************@corp.supernews.com...
Marcel wrote:
<?php

switch ($var) {

case ("02100" || "02700" || "02500"):

/*
rest of code......
*/

break;

}

?>

Does this work???? (i mean the || statement(s) in combination with a
switch
statement?


I don't know if your method works, but traditionally you made use of
switch()'s fall through:

switch($var) {
case "02100":
case "02700":
case "02500":
/* code */
break;
}

HTH,

Luke

Sorry for being so lazy...... i figured it out myself....

<?php

$var = "02700";

switch ($var) {

case ("02100" || "02700" || "02500"):

echo "<HR>Yes this works ok!!! (\$var = $var)<HR>";

break;

}

?>

So, it works!!!!

Thanks anyway!!!!

Marcel


Just like this works?

<?php

$var = "-12345";

switch ($var) {

case ("02100" || "02700" || "02500"):

echo "<HR>Yes this works ok!!! (\$var = $var)<HR>";

break;

}

?>

The result?

"Yes this works ok!!! ($var = -12345)"

.... No it doesn't... Read Luke Ross's post.

Jul 17 '05 #5

P: n/a
Carved in mystic runes upon the very living rock, the last words of
Marcel of comp.lang.php make plain:
Marcel wrote:
>
> Does this work???? (i mean the || statement(s) in combination with
> a switch statement?

Sorry for being so lazy...... i figured it out myself....

So, it works!!!!


Testing is always the best way to get an answer to a question. But you
have to test thoroughly: as John Smith pointed out, this construction
will catch everything. You can see what's happening if you do this:

if ("02100" || "02700" || "02500") {
echo "True";
}

That expression will always evaluate to true. Your case statement then,
is just a long way of writing

case true:

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.