FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » switch with range of comparisons
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: switch with range of comparisons [message #184729 is a reply to message #184636] Thu, 23 January 2014 00:18 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Mon, 13 Jan 2014 18:35:07 -0500, richard wrote:

> What I want to do is to have one case for all 26 letters of the alphabet
> without having to use ||.

You can only match 1 possible value of the test variable with each case
statement in php.

You can not match multiple possible values of the test variable in a
single case statement in php.

If you wish to match multiple values, you can stack case statements.

The case statement comparison is a coercive equality test, ie it will
coerce both objects being compared so that it can make a meaningful test
for equality.

Here is an example of multiple tests all executing the same code branch
in a switch statement:

switch ( $x ) {

case "fish":
case "chips":
case "sausages":
case "peas":
case "beans":
case "burgers":
echo "food";
break;

case "salt":
case "pepper":
case "vinegar":
case "ketchup":
echo "Condiment";
break;

case "water":
case "beer":
case "whisky":
case "vodka":
case "cola":
case "milk":
case "coffee":
echo "beverage";
break;

default:
echo "Are you sure you want to consume that?";
break;

}

I eagerly await your next example of how to fuck up a switch statement.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: When a random file is not found then what?
Next Topic: [CM] Falkvinge: MtGox had custom SSHD written in PHP
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Sep 30 04:12:43 GMT 2024

Total time taken to generate the page: 0.04203 seconds