Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #12705
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: switch with range of comparisons |
| Date | 2014-01-23 00:18 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <lbpn4v$668$5@dont-email.me> (permalink) |
| References | <19ycnlnq3bdux$.jp8vxofzg98i.dlg@40tude.net> |
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@gmail.com
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
switch with range of comparisons richard <noreply@example.com> - 2014-01-13 18:35 -0500
Re: switch with range of comparisons Scott Johnson <noonehome@chalupasworld.com> - 2014-01-13 16:14 -0800
Re: switch with range of comparisons "Beauregard T. Shagnasty" <a.nony.mous@example.invalid> - 2014-01-14 00:30 +0000
Re: switch with range of comparisons Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-14 01:36 +0000
Re: switch with range of comparisons "Peter H. Coffin" <hellsop@ninehells.com> - 2014-01-13 18:54 -0600
Re: switch with range of comparisons Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-01-14 01:26 +0000
Re: switch with range of comparisons bill <william@TechServSys.com> - 2014-01-14 06:38 -0500
Re: switch with range of comparisons daniel@honestempire.com - 2014-01-22 14:44 -0800
Re: switch with range of comparisons Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-23 00:18 +0000
Re: switch with range of comparisons testmehere@gmail.com (Jason) - 2014-03-11 18:51 -0500
csiph-web