Php 如何获得投掷的硬币的名称,而不是数字
我做了一个掷硬币游戏。它由三行组成。我要翻盖号码,翻盖是什么,硬币是什么。除了翻转的名称(正面、反面)之外,我所有的都有。我只得到我为翻转设置的数字。我怎样才能让对方说出单词“heads”代表0或“tails”代表1,而不仅仅是0或1。我试着在回音中这样做,但我仍然收到了号码。这是我的代码Php 如何获得投掷的硬币的名称,而不是数字,php,Php,我做了一个掷硬币游戏。它由三行组成。我要翻盖号码,翻盖是什么,硬币是什么。除了翻转的名称(正面、反面)之外,我所有的都有。我只得到我为翻转设置的数字。我怎样才能让对方说出单词“heads”代表0或“tails”代表1,而不仅仅是0或1。我试着在回音中这样做,但我仍然收到了号码。这是我的代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="keywords"
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="keywords" content="insert, keywords, here">
<meta name="description" content="Insert description here">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Coin</title>
</head>
<body>
<header>
<h1> Coin</h1>
</header>
<nav>
</nav>
<section>
<h2> Coin</h2>
<?php
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "</tr>";
echo "<thead>";
echo "<tbody>";
for($i=0; $i<20; $i++){
//0 is heads
//1 is tails
$result = rand(0, 1);
$count = $i+1;
echo "<tr>";
echo "<td>". $count . "</td>";
echo "<td>" . $result . "</td>";
if($result == 0){
echo "<td><img src=\"heads.jpg\" alt=\"heads\"></td>";
} else {
echo "<td><img src=\"tails.jpg\" alt=\"tails\"></td>";
}
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>
</section>
</body>
</html>
硬币
硬币
硬币
您可以将数字映射到所需的单词。例如:
$headsTailsMapping = [];
$headsTailsMapping[0] = "heads"
$headsTailsMapping[1] = "tails"
...
echo "<td>" . $headsTailsMapping[$result] . "</td>";
$headsTailsMapping=[];
$headsTailsMapping[0]=“heads”
$headsTailsMapping[1]=“tails”
...
“回声”$头饰映射[$result]。"";