抽獎大轉盤演示:http://www.sucaihuo.com/php/3301.html function getRand($proArr, $proCount) { $result = ''; $proSum = 0; foreach ($proCount as $key => $val) { if ($val <= 0) { continue; } else { $proSum = $proSum + $proArr[$key]; } } foreach ($proArr as $key => $proCur) { if ($proCount[$key] <= 0) { continue; } else { $randNum = mt_rand(1, $proSum); if ($randNum <= $proCur) { $result = $key; break; } else { $proSum -= $proCur; } } } unset($proArr); return $result; }
$prizes = array( 0 => array( "id" => 0, //中獎id "name" => "謝謝參與", //獎品名稱 "count" => "100", //庫存 ), 1 => array( "id" => 1, "name" => "羅浮山門票", "count" => "40", ), 2 => array( "id" => 2, "name" => "羅浮山嘉寶田溫泉體驗券", "count" => "40", ), 3 => array( "id" => 3, "name" => "精美旅遊書籍《山水釀惠州》", "count" => "40", ), 4 => array( "id" => 4, "name" => "碧海灣漂流門票", "count" => "40", ), 5 => array( "id" => 5, "name" => "南崑山門票", "count" => "40", ), 6 => array( "id" => 6, "name" => "雲頂溫泉精美禮品", "count" => "40", ), );