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

Home » Imported messages » comp.lang.php » Switch question
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Switch question [message #184613 is a reply to message #184603] Sun, 12 January 2014 23:14 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Sun, 12 Jan 2014 12:26:01 -0500, richard wrote:

> On Sun, 12 Jan 2014 17:18:59 +0000 (UTC), Denis McMahon wrote:
>
>> On Sun, 12 Jan 2014 11:48:48 -0500, richard wrote:
>>
>>> The manual for PHP switch shows no examples on how to use multiple
>>> values for the same case.
>>> In liberty basic I would use the following:
>>> case 1,2,3,4 case "A","B","C"
>>>
>>> What is the equivelant in PHP?
>>>
>>> I use the following code to acquire a value:
>>> $value=$_GET['v'];
>>> switch ($value){
>>> case "A";
>>
>> This is fucked up, despite what you may believe ":" is not the same as
>> ";"
>>
>>> echo "Does Not Work!";
>>> case A:
>>> echo "Does Not Work!";
>>> }
>>>
>>> So what is the proper way to ensure the proper case is found
>>> correctly?
>>
>> You seem to have missed the paragraph beginning "It is important to
>> understand how the switch statement is executed in order to avoid
>> mistakes." on the manual page. This paragraph answers your question.
>
> for once I get to say, to you, >>>> RTFM!
> : is used for constants.
> ; is used for strings.

Yes, I wasn't aware that ; could be used instead of :, however you fucked
up when you said ": is used for constants. ; is used for strings."

Nice to see you're still on form with the fuck-ups.

> As usuaul, I find the answer to my question.
> Instead of commas, use ||.
>
> case 1 || 2 || 3:
> case "A" || "B" || "C";
>
> The syntax is correct!

The syntax may be valid php syntax, but I'll bet any money you like that
the code doesn't do what you expect under all operating conditions,
because you have fucked up yet again.

Here is a simple program which demonstrates your fuck-up:

<?php
function test($x){
echo "testing {$x} for \"fred\", \"jim\" or \"sue\"\n";
switch($x){
case "fred"||"jim"||"sue":echo" match\n";break;
default;echo" no match\n";break;
}
}
$names = array("pete","fred","alan","sue","andy","jim","hank","richard ");
foreach($names as $name)test($name);



--
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
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: signed int64 pack/unpack
Next Topic: Trouble connecting to a PHP SoapServer module
Goto Forum:
  

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

Current Time: Fri Nov 22 12:24:13 GMT 2024

Total time taken to generate the page: 0.04351 seconds