我正在制作一个小游戏,只有当套装和号码与随机选择的号码和套装匹配时才会显示卡片。代码如下:
<?php
$suite['heart'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
$suite['spade'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
$suite['diamond'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
$suite['club'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
$suit1 = array_rand($suite);
$suit2 = array_rand($suite);
$card1 = array_rand($suite[$suit1]);
$card2 = array_rand($suite[$suit2]);
$card_1 = $suite[$suit1][$card1];
$card_2 = $suite[$suit2][$card2];
function jqk($n){
if($n == 11 && $suit1 == 'club'){
return "<img src='img/clubs_J.png'>";
} else{
return "J";
}
else if ($n==12){
return 'Q';
}
else if ($n==13){
return 'K';
} else {
return $n;
}
}
if($card_1 <= $card_2){
$lowcard = $card_1;
print "The Low Card is ".jqk($lowcard)."<br />";
} elseif ($card_1 >= $card_2){
$highcard = $card_1;
print "The High Card ".jqk($highcard)."<br />";
}
if($card_1 <= $card_2){
$highcard = $card_2;
print "The High Card is ".jqk($highcard)."<br />";
} elseif ($card_1 >= $card_2){
$lowcard = $card_2;
print "The Low Card ".jqk($lowcard)."<br />";
}
?>
我的问题是,输出绕过了对 $suit1 的检查,并且所有匹配 11 的数字都显示了图像。先感谢您