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 #185209 is a reply to message #184729] Tue, 11 March 2014 23:51 Go to previous message
testmehere is currently offline  testmehere
Messages: 1
Registered: March 2014
Karma:
Junior Member
Denis McMahon wrote:
>
> 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.
>



--
----== posted via BitOnWire.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:11:04 GMT 2024

Total time taken to generate the page: 0.05524 seconds