473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Switch statement

<?php

switch ($var) {

case ("02100" || "02700" || "02500"):

/*
rest of code......
*/

break;

}

?>

Does this work???? (i mean the || statement(s) in combination with a switch
statement?

Marcel
Jul 17 '05 #1
5 2555
Marcel wrote:
<?php

switch ($var) {

case ("02100" || "02700" || "02500"):

/*
rest of code......
*/

break;

}

?>

Does this work???? (i mean the || statement(s) in combination with a switch
statement?


I don't know if your method works, but traditionally you made use of
switch()'s fall through:

switch($var) {
case "02100":
case "02700":
case "02500":
/* code */
break;
}

HTH,

Luke

Jul 17 '05 #2
Luke Ross wrote:
Marcel wrote:
<?php

switch ($var) {

case ("02100" || "02700" || "02500"):

/*
rest of code......
*/

break;

}

?>

Does this work???? (i mean the || statement(s) in combination with a
switch
statement?

I don't know if your method works, but traditionally you made use of
switch()'s fall through:

switch($var) {
case "02100":
case "02700":
case "02500":
/* code */
break;
}

HTH,

Luke


Also try to use single quotes instead of double, otherwise the PHP
parser has to parse the contents twice.

switch($var) {
case '02100':
case '02700':
case '02500':
/* code */
break;
}

Grant.
Jul 17 '05 #3

"Luke Ross" <lu******@sys3175.co.uk> schreef in bericht
news:vp************@corp.supernews.com...
Marcel wrote:
<?php

switch ($var) {

case ("02100" || "02700" || "02500"):

/*
rest of code......
*/

break;

}

?>

Does this work???? (i mean the || statement(s) in combination with a switch statement?


I don't know if your method works, but traditionally you made use of
switch()'s fall through:

switch($var) {
case "02100":
case "02700":
case "02500":
/* code */
break;
}

HTH,

Luke


Sorry for being so lazy...... i figured it out myself....

<?php

$var = "02700";

switch ($var) {

case ("02100" || "02700" || "02500"):

echo "<HR>Yes this works ok!!! (\$var = $var)<HR>";

break;

}

?>

So, it works!!!!

Thanks anyway!!!!

Marcel
Jul 17 '05 #4
Marcel wrote:
"Luke Ross" <lu******@sys3175.co.uk> schreef in bericht
news:vp************@corp.supernews.com...
Marcel wrote:
<?php

switch ($var) {

case ("02100" || "02700" || "02500"):

/*
rest of code......
*/

break;

}

?>

Does this work???? (i mean the || statement(s) in combination with a
switch
statement?


I don't know if your method works, but traditionally you made use of
switch()'s fall through:

switch($var) {
case "02100":
case "02700":
case "02500":
/* code */
break;
}

HTH,

Luke

Sorry for being so lazy...... i figured it out myself....

<?php

$var = "02700";

switch ($var) {

case ("02100" || "02700" || "02500"):

echo "<HR>Yes this works ok!!! (\$var = $var)<HR>";

break;

}

?>

So, it works!!!!

Thanks anyway!!!!

Marcel


Just like this works?

<?php

$var = "-12345";

switch ($var) {

case ("02100" || "02700" || "02500"):

echo "<HR>Yes this works ok!!! (\$var = $var)<HR>";

break;

}

?>

The result?

"Yes this works ok!!! ($var = -12345)"

.... No it doesn't... Read Luke Ross's post.

Jul 17 '05 #5
Carved in mystic runes upon the very living rock, the last words of
Marcel of comp.lang.php make plain:
Marcel wrote:
>
> Does this work???? (i mean the || statement(s) in combination with
> a switch statement?

Sorry for being so lazy...... i figured it out myself....

So, it works!!!!


Testing is always the best way to get an answer to a question. But you
have to test thoroughly: as John Smith pointed out, this construction
will catch everything. You can see what's happening if you do this:

if ("02100" || "02700" || "02500") {
echo "True";
}

That expression will always evaluate to true. Your case statement then,
is just a long way of writing

case true:

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
35
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
17
by: prafulla | last post by:
Hi all, I don't have a copy of C standard at hand and so anyone of you can help me. I have always wondered how switch statements are so efficient in jumping to the right case (if any)? Can...
5
by: Alvin Bruney | last post by:
Is a switch more efficient than an if statement? I observe thru the debugger that a switch statement jumps directly to its case handler where as an if statement examines all conditions...
3
by: pgraeve | last post by:
I am a convert from VB to C# so bear with me on this "conversion" question C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. ...
27
by: Yuriy Solodkyy | last post by:
Hi VS 2005 beta 2 successfully compiles the following: using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program {
25
by: v4vijayakumar | last post by:
'continue' within switch actually associated with the outer 'while' loop. Is this behavior protable? int ch = '\n'; while (true) { switch(ch) { case '\n': cout << "test"; continue; } }
12
by: | last post by:
Is it fine to call another method from Switch? Eg. Switch (stringVar) { case ("a"): somVar = "whatever"; Another_Method(); //call another method return;
2
by: Phillip B Oldham | last post by:
What would be the optimal/pythonic way to subject an object to a number of tests (based on the object's attributes) and redirect program flow? Say I had the following: pets = {'name':...
13
by: Satya | last post by:
Hi everyone, This is the first time iam posting excuse me if iam making any mistake. My question is iam using a switch case statement in which i have around 100 case statements to compare. so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.