The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> PHP Switch, Multiple cases
Dag
post Jul 2 2017, 05:30 AM
Post #1


Advanced Member
****

Group: Members
Posts: 107
Joined: 24-October 06
Member No.: 549



This works as expected:
(/?lg=d1 or /?lg=d2)
CODE

$lg = $_GET['lg'];
switch ($lg) {
    case 'd2': $val = 'VALUE 2'; break;
    case 'd1': $val = 'VALUE 1'; break;
    default: $val = 'VALUE 1'; break;
}
echo $lg;
echo "<br>\n";
echo $val;
die();

But this one makes me mad:
CODE

$lg = $_GET['lg'];
switch ($lg) {
    case 'd2' || 'd3': $val = 'VALUE 2'; break;
    case 'd1' || 'd4': $val = 'VALUE 1'; break;
    default: $val = 'VALUE 1'; break;
}
echo $lg;
echo "<br>\n";
echo $val;
die();

What I am doing wrong?
PHP Version 5.3.13
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jul 2 2017, 09:54 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



The PHP switch works pretty much like the Javascript version.
CODE
$lg = $_GET['lg'];
switch ($lg) {
    case 'd2':
    case 'd3':
     $val = 'VALUE 2';
     break;
    case 'd1':
    case 'd4':
     $val = 'VALUE 1';
     break;
    default:
     $val = 'VALUE 1';
     break;
}
echo $lg;
echo "<br>\n";
echo $val;
die();
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Dag
post Jul 2 2017, 01:04 PM
Post #3


Advanced Member
****

Group: Members
Posts: 107
Joined: 24-October 06
Member No.: 549



Thanks Charles.
I saw that but couldn get that it is my case...

Too Much VBA Makes You Short Sighted tongue.gif

QUOTE(CharlesEF @ Jul 2 2017, 06:54 PM) *

The PHP switch works pretty much like the Javascript version.
CODE
$lg = $_GET['lg'];
switch ($lg) {
    case 'd2':
    case 'd3':
     $val = 'VALUE 2';
     break;
    case 'd1':
    case 'd4':
     $val = 'VALUE 1';
     break;
    default:
     $val = 'VALUE 1';
     break;
}
echo $lg;
echo "<br>\n";
echo $val;
die();


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th March 2024 - 04:04 AM