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 #184604 is a reply to message #184599] Sun, 12 January 2014 17:34 Go to previous messageGo to previous message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma:
Senior Member
richard the sto0pid wrote:

[about switch]

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

So why not write your site in that language?

> I would use the following:
> case 1,2,3,4 case "A","B","C"
>
> What is the equivelant in PHP?

It's going to be similar. Above, you've not mixed string and numeric; why
would you do it below?

> I use the following code to acquire a value:
> $value=$_GET['v'];
> switch ($value){
> case "A"; <------- string
> echo "Does Not Work!";
> case A: <------- numeric (or.. not really anything!)
> echo "Does Not Work!";
> }

You've forgotten break and default, and how would you know which was
chosen if both echo statements are identical?

> So what is the proper way to ensure the proper case is found correctly?

switch($nmonth) {
case "01": $cmonth="January"; break;
case "02": $cmonth="February"; break;
case "03": $cmonth="March"; break;
case "04": $cmonth="April"; break;
case "05": $cmonth="May"; break;
case "06": $cmonth="June"; break;
case "07": $cmonth="July"; break;
case "08": $cmonth="August"; break;
case "09": $cmonth="September"; break;
case "10": $cmonth="October"; break;
case "11": $cmonth="November"; break;
case "12": $cmonth="December"; break;
default: $cmonth="Not a valid month number"; break;
}
echo $cmonth;

You should find a new hobby.

--
-bts
-This space for rent, but the price is high
[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: Sat Nov 30 21:19:06 GMT 2024

Total time taken to generate the page: 0.06679 seconds