Kahuki Webmaster Forum  

Go Back   Kahuki Webmaster Forum > Website Development & Management > Programming > PHP

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-15-2007, 07:49 PM
Rookie
 
Join Date: Dec 2007
Posts: 43
jgrant is on a distinguished road
Random Events in PHP (Streamlined)

PHP Code:
<?php

## To change the odds, change the second number in the rand() function. ##

$enum floor(rand(0,20));
if(
$enum == 1){
    
    
## Write the events in here with the opener: $event[] = "#your event#"; ##
    
    
$event[] = "";
    
    
## This will pick a random event and show it ##
    
    
$renum floor(rand(0,count($event)));
    echo 
$event[$renum];
}

?>
Alright, that's the code I use for random events. Think Neopets. That's the best example out there.
When you browse pages, after awhile a message will pop up on your page and say:
"You found 100 Money on the ground!~"
Well, that is basically what this script does.

So, I like running my pages fast. I streamline all my code to use the least code possible, and reproduce the same effect the best I can.

Anyways, my question is:
Is this the fastest way?~


Also, Feel free to use this code for anything you wish. Share it, Use it, Implement it.

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:46 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0