Wrox Programmer Forums
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 9th, 2005, 10:19 AM
Authorized User
Join Date: Jul 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajuru Send a message via Yahoo to rajuru
Default Switch

I want to create switch statement depending multiple value

case "Register","Signup","New Member":
  include ("reg.php");

can i write code in this way? or is there any alternative way
I don't like the follwoing code

case "Register":
  include ('reg.php');
case "Signup":
  include ('reg.php')

Best Regard:
Md. Zakir Hossain (Raju)
Best Regard:
Md. Zakir Hossain (Raju)

www.rajuru.xenexbd.com - my blog with PHP scripts, PHP Book Review and many more
Old February 9th, 2005, 10:26 AM
Registered User
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Asix

Generally speaking, you could write the first choice, but it could cause problems on many web servers, but if you use the second code, it will work fine on all web servers, without the need to manually alter PHP configuration. I think that the second way is the safest way to use Switch command, and that structure of code is much better than the first one for many reasons.

Old February 9th, 2005, 11:24 AM
Authorized User
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts

why don't you just include it in an if statement? Personally, I rather do an if/elseif statement over switch statements; however, switch statements do give you a nice layout for the reader.

if($action == "register" || $action == "signup" || $action == "new member"){

also be careful with the switch statement when you are comparing integers and strings together.

Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq

Similar Threads
Thread Thread Starter Forum Replies Last Post
switch statement crmpicco Javascript How-To 3 March 9th, 2015 10:37 PM
Switch mamatharocks Biztalk 0 May 22nd, 2008 11:29 PM
if or switch Dink Classic ASP Databases 2 February 4th, 2007 04:00 AM
switch statement seymour_glass C# 5 January 24th, 2007 12:08 AM
C# switch statement nalla General .NET 4 December 14th, 2005 05:31 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.