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
Switch to threaded view of this topic Create a new topic Submit Reply
switch with range of comparisons [message #184636] Mon, 13 January 2014 23:35 Go to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
switch ($value){

case "A">="Z";


}

Would this be allowed?

What I want to do is to have one case for all 26 letters of the alphabet
without having to use ||.
Re: switch with range of comparisons [message #184638 is a reply to message #184636] Tue, 14 January 2014 00:14 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
On 1/13/2014 3:35 PM, richard wrote:
> switch ($value){
>
> case "A">="Z";
>
>
> }
>
> Would this be allowed?
>
> What I want to do is to have one case for all 26 letters of the alphabet
> without having to use ||.
>

Why don't you venture into the if()..elseif() schema.

Or...

have 26 cases that just drop thru to the last one that does the processing.

This was you can eventually add needed code for the ones that need it.

Scotty
Re: switch with range of comparisons [message #184639 is a reply to message #184636] Tue, 14 January 2014 00:30 Go to previous messageGo to next message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
richard the sto0pid wrote:

> switch ($value){
>
> case "A">="Z";
>
> }
>
> Would this be allowed?

How will "A" ever be equal-to or greater-than "Z"?

> What I want to do is to have one case for all 26 letters of the alphabet
> without having to use ||.

Why would you want to use switch for only one condition?

Go to your local big box store and purchase a carton of Logic.

--
-bts
-who opened a Pandora's Box, introducing RtS to "switch"
Re: switch with range of comparisons [message #184640 is a reply to message #184636] Tue, 14 January 2014 00:54 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Mon, 13 Jan 2014 18:35:07 -0500, richard wrote:
> switch ($value){
>
> case "A">="Z";
>
>
> }
>
> Would this be allowed?

Allowed? Yes. Does it solve your problem? Probably not. That case will
never be executed unless $value contains something that evaluates to
false. As "A">="Z" does.

> What I want to do is to have one case for all 26 letters of the
> alphabet without having to use ||.

Back further up. Most ways of answering that question are probably
useless. What problem are you trying to solve?

--
10. I will not interrogate my enemies in the inner sanctum -- a small
hotel well outside my borders will work just as well.
--Peter Anspach's list of things to do as an Evil Overlord
Re: switch with range of comparisons [message #184641 is a reply to message #184636] Tue, 14 January 2014 01:26 Go to previous messageGo to next message
Doug Miller is currently offline  Doug Miller
Messages: 171
Registered: August 2011
Karma: 0
Senior Member
richard <noreply(at)example(dot)com> wrote in news:19ycnlnq3bdux$.jp8vxofzg98i.dlg@
40tude.net:

> switch ($value){
>
> case "A">="Z";
>
>
> }
>
> Would this be allowed?

Yes, it's allowed.

It's equivalent to

switch ($value) {
case false:
....
}

> What I want to do is to have one case for all 26 letters of the alphabet
> without having to use ||.

That won't do what you want. Neither will ||, for reasons that have already been explained.

Why not just code a simple if statement to test if $value is between "A" and "Z" ?
Re: switch with range of comparisons [message #184642 is a reply to message #184639] Tue, 14 January 2014 01:36 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Tue, 14 Jan 2014 00:30:00 +0000, Beauregard T. Shagnasty wrote:

> richard the sto0pid wrote:
>
>> switch ($value){
>>
>> case "A">="Z";
>>
>> }
>>
>> Would this be allowed?
>
> How will "A" ever be equal-to or greater-than "Z"?
>
>> What I want to do is to have one case for all 26 letters of the
>> alphabet without having to use ||.
>
> Why would you want to use switch for only one condition?
>
> Go to your local big box store and purchase a carton of Logic.

I think what richard meant to ask was:

will

case >=A && <=Z :

work

But he couldn't even figure that out, and he obviously didn't run my
example php program that attempted to show him that he was working from a
flawed understanding.

Oh well, roll on the fucked up code.

As for whether it will work or not, well I'm buggered if I can be arsed
to help richard any more. He can find out for himself.

And now for a special message to richard:

richard, your comprehension of how switch statements work is currently so
fucked up that you are presently incapable of coding one that does what
you want, even if it appears to do so under test conditions with the
limited test data that you feed it. I strongly suggest you take a
sabbatical from your project to learn basic php programming syntax before
doing any more work on your website. 50 years might do it, although with
your current record, it might be best to set aside at least 300.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: switch with range of comparisons [message #184643 is a reply to message #184641] Tue, 14 January 2014 11:38 Go to previous messageGo to next message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma: 0
Senior Member
On 1/13/2014 8:26 PM, Doug Miller wrote:

> }
>
>> What I want to do is to have one case for all 26 letters of the alphabet
>> without having to use ||.
>
> That won't do what you want. Neither will ||, for reasons that have already been explained.
>
> Why not just code a simple if statement to test if $value is between "A" and "Z" ?
>
>
>
>
>
should we tell richard about regex ?
no !
Re: switch with range of comparisons [message #184727 is a reply to message #184636] Wed, 22 January 2014 22:44 Go to previous messageGo to next message
daniel is currently offline  daniel
Messages: 1
Registered: January 2014
Karma: 0
Junior Member
On Monday, 13 January 2014 23:35:07 UTC, richard wrote:
> switch ($value){
>
>
>
> case "A">="Z";
>
>
>
>
>
> }
>
>
>
> Would this be allowed?
>
>
>
> What I want to do is to have one case for all 26 letters of the alphabet
>
> without having to use ||.

Take a look at preg_match() or ctype_alpha()

http://uk1.php.net/preg_match
http://www.php.net/manual/en/function.ctype-alpha.php
Re: switch with range of comparisons [message #184729 is a reply to message #184636] Thu, 23 January 2014 00:18 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
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: 0
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 ==----
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Wed Dec 18 04:13:22 GMT 2024

Total time taken to generate the page: 0.02532 seconds