<?php
$your = array("6","25","22","16","17","18");
//mt_srand((double)microtime()*1000000);
$lottery[] = array();
$n = 6;
for ($i = 1; $i <= $n; $i++) {
$number = rand(1,42);
if (in_array($number, $lottery)) { //如果已產生過迴圈重跑 in_array --- 搜尋陣列中值是否存在
$i--;
}else{
$lottery[] = $number; //若無重復則 將亂數塞入陣列
}
}
echo "中獎號碼 : ";
for ($i = 1; $i <= $n; $i++) {
for ($j = 0; $j < $n; $j++) {
// echo $lottery[$i];
// echo $your[$i-1];
if($lottery[$i] == $your[$j])
echo $lottery[$i]." ";
}
}
?> |