Jump to content
Sign in to follow this  
Burns

Switches

Recommended Posts

As i had to find out, you can only do a limited number of things with if-functions, so here is some very basic switch that allows to make basically infinte different events happen in the same item, and with the same activator:

[php]@vc=date('z');
@vd=@vc%7+3; //mod-calculation
//echo @vd; <-- used for test purposes, to see if mod and the cases work right
//echo"<br>";

switch (@vd) { //switch-operator searches for the right case and does the things you told it to do, in this case just echo
case 7: echo "monday";break; // always use 'break;' at the end of the case, else you will get all cases after the right one showing up!!
case 8: echo "tuesday"; break;
case 9: echo "wednesday"; break;
case 3: echo "thursay"; break;
case 4: echo "friday"; break;
case 5: echo "saturday"; break;
case 6: echo "sunday"; break;}[/php]

this one is a pretty simple useage to give out the day of the week, but switches can also easily be combined with keys (strings go in between "", like 'case "first-key":', 'case "second key":' etc.), random event-generators, whatever you want it to do^^

switches also offer a default-option, which is obviously not fitting for my little example code, but if no case mathces, which might happen with keys, you simple add

[php]default: echo "sorry, you don't have the key";[/php]

after the last case (BEFORE '}'!) Edited by Burns

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Forum Statistics

    15,832
    Total Topics
    173,490
    Total Posts
  • Recently Browsing

    No registered users viewing this page.

  • Upcoming Events

    No upcoming events found
  • Recent Event Reviews

×
×
  • Create New...