douxu2081 2016-04-13 16:26
浏览 21

如何获得投掷的硬币的名称而不是数字

I made a flip a coin game. It consists of three rows. I want the flip number what the flip was and the coin. I have all except the name of the flip like (heads,tails) I am only getting the number that I set for the flip. How do I get the flip to say the word 'heads' for 0 or 'tails' for 1 instead of just 0 or 1. I tried to do it in an echo I still received the number.this is the code I have

<!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>
  • 写回答

1条回答 默认 最新

  • duandoucou7200 2016-04-13 16:29
    关注

    You could map the number to the word you want. For example:

    $headsTailsMapping = [];
    $headsTailsMapping[0] = "heads"
    $headsTailsMapping[1] = "tails"
    ...
    echo "<td>" . $headsTailsMapping[$result] . "</td>";
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法