<body>
<?php
$face1 = "1";
$face2 = "2";
$face3 = "3";
$face4 = "4";
$face5 = "5";
$face6 = "6";
$frequency1 = 0;
$frequency2 = 0;
$frequency3 = 0;
$frequency4 = 0;
$frequency5 = 0;
$frequency6 = 0;
$result = rand(1, 6);
if ($result = 1)
$frequency1+=1;
if ($result = 2)
$frequency2+=1;
if ($result = 3)
$frequency3+=1;
if ($result = 4)
$frequency4+=1;
if ($result = 5)
$frequency5+=1;
if ($result = 6)
$frequency6+=1;
?>
<h2>Statistical analysis of results from rolling a
six‐sided die</h2>
<table width='600' border='1' cellspacing='0' cellpadding='0' align='center'>
<tr>
<th>Face</th>
<th>Frequency</th>
</tr>
<?php
define("FACE_NUM", 6);
$face_count=1;
while ($face_count<=FACE_NUM) {
$number = ${'face' . $face_count};
$frequency = ${'frequency' . $face_count};
echo "<tr>
<td> $number </td>
<td> $frequency </td>
</tr>";
$face_count++;
}
?>
</table>
<input type="submit" value="Refresh" onclick="window.location.reload()" />
</body>
</html>
When I test it in a browser, it only shows the number 1 in the column where it shows the frequency. How do I make it roll 1,000 times and then display the frequencies? What am I missing?
We're supposed to use at least one loop, so that is required in the answer. The frequencies of each number on the die need to be displayed in a table.