2016-04-13 32 views
0

我做了一个掷硬币游戏。它由三排组成。我想要翻盖的数字是什么,以及硬币。除了翻盖的名字(头部,尾巴)之外,我都拥有了所有的名字,我只是获得了我为翻盖设置的数字。我如何获得翻转单词'head'为0或'tails'为1而不是0或1。我试图用回声做我仍然收到的号码。这是我的代码如何获得抛硬币的名称而不是数字

<!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> 

回答

0

你可以将数字映射到你想要的单词。例如:

$headsTailsMapping = []; 
$headsTailsMapping[0] = "heads" 
$headsTailsMapping[1] = "tails" 
... 
echo "<td>" . $headsTailsMapping[$result] . "</td>"; 
相关问题