Switch Command

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swjohnson
Forum Newbie
Posts: 2
Joined: Wed Nov 12, 2008 10:36 am

Switch Command

Post by swjohnson »

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I am a dbase programmer - at least I was 15 years ago when I got burned out. This is my first serious look at reestablishing my programming skills, although I have done some HTML progrmming over the years, it left quite a bit to be desired. I am a firm believer in subroutines, something HTML couldn't fully accomplish. I have about 30 pages on the website I am developing and don't want to have to maintain 30 fully coded pages.

Are there any major problems with the concept of the following code? (I substituted [] for <>)

Code: Select all

<? php
 
include(header.php)
 
$bodytext = 0; //This actually gets its value from the header in the mapped areas so I will delete this from the real code
 
switch ($bodytext) {
 
   case "1" :
   include(aboutus.php);
   break;
 
   case "2" :
   include(contactus.php);
   break;
 
   default :
   include(index.php);
   break;
 
   }
 
include(footer.php)
 
?>
Thanks in advance,

Steve


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: Switch Command

Post by infolock »

No, except if you take off the "" around the case statements it will be evaluated as an integer instead of a string, meaning on a low level point of view it will be executed quicker ;)

but that's just me being very picky..
swjohnson
Forum Newbie
Posts: 2
Joined: Wed Nov 12, 2008 10:36 am

Re: Switch Command

Post by swjohnson »

DUH! Thanks for the suggestion, Jonathon. And thanks for the rapid response.
Steve

I notice there is no smilie for slapping my forehead!
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: Switch Command

Post by infolock »

haha, but there is one for banging it against a brick wall :banghead: :D
Post Reply