|
 |
|
พี่ ๆคะ ใครมีโปรแกรมสุ่มของรางวัลที่เขียนด้วย PHP บ้างคะ |
|
 |
|
|
 |
 |
|
ลองเอาไปประยุกต์ต่อน่ะ
Code (PHP)
<?php
session_start();
$arr = array("iphone","nokia","LG","pencil","bag","shirt","apartment");
echo "ของรางวัลทั้งหมด <BR>";
foreach($arr as $a){
echo $a." <br>";
}
?>
<form method="post" action="">
<input type="submit" value="reset" name="reset">
<input type="submit" value ="random" name="random">
</form>
<?php
if(!isset($_SESSION[items]) || isset($_POST[reset]))
{
$_SESSION[items]=$arr;
}
else if(count($_SESSION[items])==0)
{
echo "รางวัลถูกจับหมดแล้ว";
}
else if(isset($_POST[random]) )
{
shuffle($_SESSION[items]);
$rand=array_rand($_SESSION[items]);
echo "รางวัลที่จับได้ :".$_SESSION[items][$rand]."<BR>";
unset($_SESSION[items][$rand]);
echo "ของรางวัลที่เหลือ<BR>";
foreach($_SESSION[items] as $i){
echo $i."<BR>";
}
}
?>
|
 |
 |
 |
 |
Date :
2010-01-06 17:19:59 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|