| 發表文章 | 發起投票 |
《膠登學院》PHP改正篇 Vol. 1
<?
if($_GET['action'] == 'play') {
switch($_POST['colour']) {
case 'all':
$ball = array();
while(count($ball) < 6) {
$random_number = rand(1, 49);
$stop = false;
while(!$stop) {
if(array_search($random_number, $ball) === false) {
array_push($ball, $random_number);
$stop = true;
} else {
$random_number = rand(1, 49);
}
}
}
if($mode == 0) {
print join(', ', $ball);
} else {
foreach($ball as $value) {
echo "<img />";
}
}
break;
case 'red':
$ball = array();
while(count($ball) < 6) {
$ball_number = array(1, 2, 7, 8, 12, 13, 18, 19, 23, 24, 29, 30, 34, 35, 40, 45, 46);
$random_number = $ball_number[rand(0, 16)];
$stop = false;
while(!$stop) {
if(array_search($random_number, $ball) === false) {
array_push($ball, $random_number);
$stop = true;
} else {
$random_number = $ball_number[rand(0, 16)];
}
}
}
if($mode == 0) {
print join(', ', $ball);
} else {
foreach($ball as $value) {
echo "<img />";
}
}
break;
case 'green':
$ball = array();
while(count($ball) < 6) {
$ball_number = array(5, 6, 11, 16, 17, 21, 22, 27, 28, 32, 33, 38, 39, 43, 44, 49);
$random_number = $ball_number[rand(0, 15)];
$stop = false;
while(!$stop) {
if(array_search($random_number, $ball) === false) {
array_push($ball, $random_number);
$stop = true;
} else {
$random_number = $ball_number[rand(0, 15)];
}
}
}
if($mode == 0) {
print join(', ', $ball);
} else {
foreach($ball as $value) {
echo "<img />";
}
}
break;
case 'blue':
$ball = array();
while(count($ball) < 6) {
$ball_number = array(3, 4, 9, 10, 14, 15, 20, 25, 26, 31, 36, 37, 41, 42, 47, 48);
$random_number = $ball_number[rand(0, 15)];
$stop = false;
while(!$stop) {
if(array_search($random_number, $ball) === false) {
array_push($ball, $random_number);
$stop = true;
} else {
$random_number = $ball_number[rand(0, 15)];
}
}
}
if($mode == 0) {
print join(', ', $ball);
} else {
foreach($ball as $value) {
echo "<img />";
}
}
break;
}
}
?>請問以上代碼有邊度寫錯/有問題

請留言一一指出

本貼文共有 0 個回覆
此貼文已鎖,將不接受回覆
| 發表文章 | 發起投票 |