Jump to content



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:

@vd=@vc%7+3; //mod-calculation
//echo @vd; <-- used for test purposes, to see if mod and the cases work right

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


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

  • Forum Statistics

    Total Topics
    Total Posts
  • Recently Browsing

    No registered users viewing this page.

  • Upcoming Events

    No upcoming events found
  • Recent Event Reviews

  • Create New...