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 #184630 is a reply to message #184599] Mon, 13 January 2014 14:32 Go to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma:
Senior Member
Am 12.01.2014 17:48, schrieb richard:

> The manual for PHP switch shows no examples on how to use multiple values
> for the same case.

1) Go to <http://php.net/manual/en>

2) Use the "Search" box to look for "switch"

3) You should find this:

<http://php.net/manual/en/control-structures.switch.php>

Cite:

The statement list for a case can also be empty, which simply passes
control into the statement list for the next case.

<?php
switch ($i) {
case 0:
case 1:
case 2:
echo "i is less than 3 but not negative";
break;
case 3:
echo "i is 3";
}
?>

> 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";
> echo "Does Not Work!";
> case A:
> echo "Does Not Work!";
> }
>
> So what is the proper way to ensure the proper case is found correctly?

switch($value)
{
case 1:
case 2:
case 3:
// dosomething
break; // <--- THIS IS IMPORTANT!

case A:
case B:
case C:
// dosomethingelse
break; // <!-- THIS IS IMPORTANT!

default:
// if nothing else matches
}


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
[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: Sun Nov 24 05:28:02 GMT 2024

Total time taken to generate the page: 0.04122 seconds