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


Member
***

Group: Members
Posts: 81
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


This is My Life
*******

Group: Members
Posts: 1,436
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


Member
***

Group: Members
Posts: 81
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
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th November 2017 - 03:25 AM