Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #12614 > unrolled thread

Switch question

Started byrichard <noreply@example.com>
First post2014-01-12 11:48 -0500
Last post2014-01-13 15:32 +0100
Articles 20 on this page of 21 — 10 participants

Back to article view | Back to comp.lang.php


Contents

  Switch question richard <noreply@example.com> - 2014-01-12 11:48 -0500
    Re: Switch question Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-12 17:18 +0000
      Re: Switch question richard <noreply@example.com> - 2014-01-12 12:26 -0500
        Re: Switch question Luuk <luuk@invalid.lan> - 2014-01-12 18:44 +0100
        Re: Switch question Evan Platt <evan@theobvious.espphotography.com.invalid> - 2014-01-12 10:47 -0800
          Re: Switch question Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-12 23:15 +0000
        Re: Switch question Norman Peelman <npeelman@cfl.rr.com> - 2014-01-12 16:07 -0500
          Re: Switch question Norman Peelman <npeelman@cfl.rr.com> - 2014-01-12 23:01 -0500
            Re: Switch question Norman Peelman <npeelman@cfl.rr.com> - 2014-01-12 23:10 -0500
              Re: Switch question Norman Peelman <npeelman@cfl.rr.com> - 2014-01-13 06:53 -0500
              Re: Switch question Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-13 13:11 +0000
        Re: Switch question Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-12 23:14 +0000
        Re: Switch question Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-01-13 01:40 +0000
          Re: Switch question The Natural Philosopher <tnp@invalid.invalid> - 2014-01-13 01:54 +0000
            Re: Switch question Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-01-13 03:19 +0000
      Re: Switch question Arno Welzel <usenet@arnowelzel.de> - 2014-01-13 15:34 +0100
    Re: Switch question Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-12 17:22 +0000
      Re: Switch question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-12 23:36 +0100
    Re: Switch question Luuk <luuk@invalid.lan> - 2014-01-12 18:21 +0100
    Re: Switch question "Beauregard T. Shagnasty" <a.nony.mous@example.invalid> - 2014-01-12 17:34 +0000
    Re: Switch question Arno Welzel <usenet@arnowelzel.de> - 2014-01-13 15:32 +0100

Page 1 of 2  [1] 2  Next page →


#12614 — Switch question

Fromrichard <noreply@example.com>
Date2014-01-12 11:48 -0500
SubjectSwitch question
Message-ID<1jvvn9b20ts0y.1vez76z3aca4b.dlg@40tude.net>
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";
  echo "Does Not Work!";
  case A:
  echo "Does Not Work!";
}

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

[toc] | [next] | [standalone]


#12615

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-01-12 17:18 +0000
Message-ID<lauiq3$mdc$1@dont-email.me>
In reply to#12614
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.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#12618

Fromrichard <noreply@example.com>
Date2014-01-12 12:26 -0500
Message-ID<1poy7ts4hdy96$.188q6380cr9m0.dlg@40tude.net>
In reply to#12615
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.

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!

[toc] | [prev] | [next] | [standalone]


#12620

FromLuuk <luuk@invalid.lan>
Date2014-01-12 18:44 +0100
Message-ID<jt0bqa-ioh.ln1@luuk.invalid.lan>
In reply to#12618
On 12-01-2014 18:26, 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:
>>
>>>
>>> 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.
>

 From the manual:
"It's possible to use a semicolon instead of a colon after a case like:"

But this has nothing to do with contants or strings, or....?

[toc] | [prev] | [next] | [standalone]


#12621

FromEvan Platt <evan@theobvious.espphotography.com.invalid>
Date2014-01-12 10:47 -0800
Message-ID<9qo5d9le806o9ud9dth4u2galquc20iq2h@4ax.com>
In reply to#12618
On Sun, 12 Jan 2014 12:26:01 -0500, richard <noreply@example.com>
wrote:

>for once I get to say, to you, >>>> RTFM!

You tried that before. You were wrong again then, too.
-- 
To reply via e-mail, remove The Obvious and .invalid from my e-mail address.

[toc] | [prev] | [next] | [standalone]


#12629

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-01-12 23:15 +0000
Message-ID<lav7mf$mdc$5@dont-email.me>
In reply to#12621
On Sun, 12 Jan 2014 10:47:55 -0800, Evan Platt wrote:

> On Sun, 12 Jan 2014 12:26:01 -0500, richard <noreply@example.com>
> wrote:
> 
>>for once I get to say, to you, >>>> RTFM!
> 
> You tried that before. You were wrong again then, too.

Actually he was right all the way up to the exclamation mark on that 
line, but then he reverted to traditional richard.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#12622

FromNorman Peelman <npeelman@cfl.rr.com>
Date2014-01-12 16:07 -0500
Message-ID<lav06t$9ql$1@dont-email.me>
In reply to#12618
On 01/12/2014 12:26 PM, 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?
>>>

   PHP does not support that method directly as you have discovered.

>>> I use the following code to acquire a value:
>>> $value=$_GET['v'];
>>> switch ($value){
>>>    case "A";
>>

   Under normal circumstances we know that $value is a string, therefor 
what is actually in $value is the question. If the code for *case "A"* 
is not being executed then $value <> A.

>> This is f'd 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?
>>

   The example above would indicate that there is a CONSTANT A that 
$value is compared against. You are mixing problems.


>> 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.
>

   Not true, the online manual simply indicates that a ; may be used 
instead of a : period. Don't know why, I'd never do it that way - seems 
to add confusion.

> 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!
>

   There is nothing wrong with that syntax. It is merely an expression 
that ends up being true or not. Using : or ; for either case works as 
tested.


-- 
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-

[toc] | [prev] | [next] | [standalone]


#12641

FromNorman Peelman <npeelman@cfl.rr.com>
Date2014-01-12 23:01 -0500
Message-ID<lavoe4$717$1@dont-email.me>
In reply to#12622
On 01/12/2014 04:07 PM, Norman Peelman wrote:
> On 01/12/2014 12:26 PM, 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?
>>>>
>
>    PHP does not support that method directly as you have discovered.
>
>>>> I use the following code to acquire a value:
>>>> $value=$_GET['v'];
>>>> switch ($value){
>>>>    case "A";
>>>
>
>    Under normal circumstances we know that $value is a string, therefor
> what is actually in $value is the question. If the code for *case "A"*
> is not being executed then $value <> A.
>
>>> This is f'd 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?
>>>
>
>    The example above would indicate that there is a CONSTANT A that
> $value is compared against. You are mixing problems.
>
>
>>> 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.
>>
>
>    Not true, the online manual simply indicates that a ; may be used
> instead of a : period. Don't know why, I'd never do it that way - seems
> to add confusion.
>
>> 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!
>>
>
>    There is nothing wrong with that syntax. It is merely an expression
> that ends up being true or not. Using : or ; for either case works as
> tested.
>
>

Doh! scratch that... doesn't work.

-- 
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-

[toc] | [prev] | [next] | [standalone]


#12642

FromNorman Peelman <npeelman@cfl.rr.com>
Date2014-01-12 23:10 -0500
Message-ID<lavov7$9t1$1@dont-email.me>
In reply to#12641
On 01/12/2014 11:01 PM, Norman Peelman wrote:
> On 01/12/2014 04:07 PM, Norman Peelman wrote:
>> On 01/12/2014 12:26 PM, 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?
>>>>>
>>
>>    PHP does not support that method directly as you have discovered.
>>
>>>>> I use the following code to acquire a value:
>>>>> $value=$_GET['v'];
>>>>> switch ($value){
>>>>>    case "A";
>>>>
>>
>>    Under normal circumstances we know that $value is a string, therefor
>> what is actually in $value is the question. If the code for *case "A"*
>> is not being executed then $value <> A.
>>
>>>> This is f'd 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?
>>>>
>>
>>    The example above would indicate that there is a CONSTANT A that
>> $value is compared against. You are mixing problems.
>>
>>
>>>> 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.
>>>
>>
>>    Not true, the online manual simply indicates that a ; may be used
>> instead of a : period. Don't know why, I'd never do it that way - seems
>> to add confusion.
>>
>>> 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!
>>>
>>
>>    There is nothing wrong with that syntax. It is merely an expression
>> that ends up being true or not. Using : or ; for either case works as
>> tested.
>>
>>
>
> Doh! scratch that... doesn't work.
>

   And yes I know why. :) It returns a boolean value. 0 does not match 
but 4 does, "D" also matches. Ha, good catch Denis and Doug!

-- 
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-

[toc] | [prev] | [next] | [standalone]


#12643

FromNorman Peelman <npeelman@cfl.rr.com>
Date2014-01-13 06:53 -0500
Message-ID<lb0k3m$ln$1@dont-email.me>
In reply to#12642
On 01/12/2014 11:10 PM, Norman Peelman wrote:
> On 01/12/2014 11:01 PM, Norman Peelman wrote:
>> On 01/12/2014 04:07 PM, Norman Peelman wrote:
>>> On 01/12/2014 12:26 PM, 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?
>>>>>>
>>>
>>>    PHP does not support that method directly as you have discovered.
>>>
>>>>>> I use the following code to acquire a value:
>>>>>> $value=$_GET['v'];
>>>>>> switch ($value){
>>>>>>    case "A";
>>>>>
>>>
>>>    Under normal circumstances we know that $value is a string, therefor
>>> what is actually in $value is the question. If the code for *case "A"*
>>> is not being executed then $value <> A.
>>>
>>>>> This is f'd 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?
>>>>>
>>>
>>>    The example above would indicate that there is a CONSTANT A that
>>> $value is compared against. You are mixing problems.
>>>
>>>
>>>>> 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.
>>>>
>>>
>>>    Not true, the online manual simply indicates that a ; may be used
>>> instead of a : period. Don't know why, I'd never do it that way - seems
>>> to add confusion.
>>>
>>>> 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!
>>>>
>>>
>>>    There is nothing wrong with that syntax. It is merely an expression
>>> that ends up being true or not. Using : or ; for either case works as
>>> tested.
>>>
>>>
>>
>> Doh! scratch that... doesn't work.
>>
>
>    And yes I know why. :) It returns a boolean value. 0 does not match
> but 4 does, "D" also matches. Ha, good catch Denis and Doug!
>

   I should state that because *1 || 2 || 3* and *"A" || "B" || "C"* 
will return a boolean (TRUE) value that:

0 (FALSE) fails to match as expected, any other number is considered TRUE.
"" and "0" (FALSE) fails to match as expected, any other non-empty 
string is considered TRUE.

   In reality the CASE expression hasn't been matched at all - not even 
when $value contains 1,2 or 3 or "A","B" or "C". Only the boolean state 
of TRUE or FALSE has been compared.

   Richard, you will need to use the standard SWITCH...CASE syntax. I 
overlooked that simple concept even as I typed it in my response.

-- 
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-

[toc] | [prev] | [next] | [standalone]


#12644

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-01-13 13:11 +0000
Message-ID<lb0ols$k2a$3@dont-email.me>
In reply to#12642
On Sun, 12 Jan 2014 23:10:14 -0500, Norman Peelman wrote:

>    And yes I know why. :) It returns a boolean value. 0 does not match
> but 4 does, "D" also matches. Ha, good catch Denis and Doug!

To be honest, the trouble with pointing out glaring errors in richardcode 
is working out which fish to shoot, because the barrel is so overcrowded.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#12628

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-01-12 23:14 +0000
Message-ID<lav7k4$mdc$4@dont-email.me>
In reply to#12618
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@gmail.com

[toc] | [prev] | [next] | [standalone]


#12634

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2014-01-13 01:40 +0000
Message-ID<XnsA2B3D24BB706Fdougmilmaccom@78.46.70.116>
In reply to#12618
richard <noreply@example.com> wrote in news:1poy7ts4hdy96$.188q6380cr9m0.dlg@
40tude.net:

> 
> case 1 || 2 || 3:
> case "A" || "B" || "C";
> 
> The syntax is correct!
> 
<snicker>
The result will not always be what you expect.

[toc] | [prev] | [next] | [standalone]


#12635

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2014-01-13 01:54 +0000
Message-ID<lavgvu$6cp$1@news.albasani.net>
In reply to#12634
On 13/01/14 01:40, Doug Miller wrote:
> richard <noreply@example.com> wrote in news:1poy7ts4hdy96$.188q6380cr9m0.dlg@
> 40tude.net:
>
>>
>> case 1 || 2 || 3:
>> case "A" || "B" || "C";
>>
>> The syntax is correct!
>>
> <snicker>
> The result will not always be what you expect.
>
Richard has very low expectations...

-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to 
lead are elected by the least capable of producing, and where the 
members of society least likely to sustain themselves or succeed, are 
rewarded with goods and services paid for by the confiscated wealth of a 
diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#12637

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2014-01-13 03:19 +0000
Message-ID<XnsA2B3E311819BCdougmilmaccom@78.46.70.116>
In reply to#12635
The Natural Philosopher <tnp@invalid.invalid> wrote in news:lavgvu$6cp$1
@news.albasani.net:

> On 13/01/14 01:40, Doug Miller wrote:
>> richard <noreply@example.com> wrote in news:1poy7ts4hdy96$.188q6380cr9m0.dlg@
>> 40tude.net:
>>
>>>
>>> case 1 || 2 || 3:
>>> case "A" || "B" || "C";
>>>
>>> The syntax is correct!
>>>
>> <snicker>
>> The result will not always be what you expect.
>>
> Richard has very low expectations...

You misspelled "abilities".

I think RtS actually has very high expectations, not only of himself -- witness his dauntless 
attempts at problems that are clearly beyond his grasp -- but also of the other members of 
this newsgroup, whom he seems to believe are under some sort of obligation to fix all his 
errors for him.

I propose that we all agree that the next time RtS insults someone who is trying to help him, 
we will all ignore everything he posts until he apologizes.

[toc] | [prev] | [next] | [standalone]


#12646

FromArno Welzel <usenet@arnowelzel.de>
Date2014-01-13 15:34 +0100
Message-ID<52D3F974.3030203@arnowelzel.de>
In reply to#12615
Am 12.01.2014 18:18, schrieb Denis McMahon:
> 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 ";"

Nope - unusual - but valid.

According to <http://php.net/manual/en/control-structures.switch.php>, cite:

It's possible to use a semicolon instead of a colon after a case like:

<?php
switch($beer)
{
    case 'tuborg';
    case 'carlsberg';
    case 'heineken';
        echo 'Good choice';
    break;
    default;
        echo 'Please make a new selection...';
    break;
}
?>



-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [next] | [standalone]


#12616

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-01-12 17:22 +0000
Message-ID<lauj08$mdc$2@dont-email.me>
In reply to#12614
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.

Oh, and just to clarify, you also need to add "I am incapable of 
reading." and "I tell lies." to your cv as well.

There is a very clear example on the manual page of matching against 
multiple values to execute a single set of statements.

Does this mean we're going to spend the next 5 years debugging your 
fucked up switch statements?

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#12626

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-01-12 23:36 +0100
Message-ID<1617716.9IWNxDE90U@PointedEars.de>
In reply to#12616
Denis McMahon wrote:

> Does this mean we're going to spend the next 5 years debugging your
> fucked up switch statements?

I should have known that “richard” would find a way to use this
for his trolling, so I should not have suggested the possibility
in <news:4555789.NIToQkNJ70@PointedEars.de>.  Sorry, my bad.


PointedEars
-- 
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
  -- Richard Cornford, comp.lang.javascript, 2011-11-14

[toc] | [prev] | [next] | [standalone]


#12617

FromLuuk <luuk@invalid.lan>
Date2014-01-12 18:21 +0100
Message-ID<3ivaqa-rhg.ln1@luuk.invalid.lan>
In reply to#12614
On 12-01-2014 17:48, richard wrote:
> The manual for PHP switch shows no examples on how to use multiple values
> for the same case.

I think this is a pretty neat example:
<?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";
}
?>
found on this page:
http://www.php.net/manual/en/control-structures.switch.php

> In liberty basic I would use the following:

this should be about PHP, not about liberty, or about basic....

[toc] | [prev] | [next] | [standalone]


#12619

From"Beauregard T. Shagnasty" <a.nony.mous@example.invalid>
Date2014-01-12 17:34 +0000
Message-ID<laujnn$cod$1@dont-email.me>
In reply to#12614
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

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.php


csiph-web