logoWebbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbserv1-dice/exercises/

dice-1.php
dice-2.php
dice-3.php
dice4/
dice5/
dice6/
dice7/

dice-1.php

31 lines UTF-8 Unix (LF)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Tärningsexempel</title>
</head>

<body>
<h1>En tärning</h1>
<p>Tärningen kastas 6 gånger, här är resultatet.</p>

<?php
// To save the outcome of each dice roll
$rolls = array();

// Roll the dice
$times = 6;
for(
$i = 0; $i < $times; $i++) {
  
$rolls[] = rand(1, 6);
}

// Print out the results
$html = "<ul>";
foreach(
$rolls as $val) {
  
$html .= "<li>{$val}</li>";
}
$html .= "</ul>";
?>
<?=$html?>
</body>
</html>