Jump to content

Switches


Burns

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 '}'!)

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Forum Statistics

    16,149
    Total Topics
    176,384
    Total Posts
  • Recently Browsing

    No registered users viewing this page.

  • Upcoming Events

    No upcoming events found
  • Recent Event Reviews

×
×
  • Create New...