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


Groups > comp.lang.php > #12645

Re: Switch question

From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: Switch question
Date 2014-01-13 15:32 +0100
Message-ID <52D3F916.7030407@arnowelzel.de> (permalink)
References <1jvvn9b20ts0y.1vez76z3aca4b.dlg@40tude.net>

Show all headers | View raw


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

Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

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

csiph-web