-
Notifications
You must be signed in to change notification settings - Fork 1
/
02-CarRandomizer.php
79 lines (68 loc) · 1.34 KB
/
02-CarRandomizer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html>
<head>
<title>02. Car Randomizer</title>
<style>
table {
border-collapse: collapse;
}
table thead tr td {
background: #445566!important;
color: #fff;
}
table td {
border: solid 1px #cecece;
padding: 12px;
}
table td:first-child {
font-style: italic;
background: #9056df;
color: #fff;
}
</style>
</head>
<body>
<form action="" method="GET">
<label for="cars">Enter cars </label>
<input type="text" id="cars" name="cars" />
<input type="submit" name="submit" value="Show result" />
</form>
<?php
function generateRandomColor() {
$colors = array("Red", "Yellow", "Blue", "Black", "White");
return $colors[rand(0, count($colors) - 1)];
}
function generateRandomQuantity() {
return rand(1, 5);
}
if($_GET && isset($_GET['submit'])):
$input = $_GET['cars'];
$cars = explode(", ", $input);
?>
<table>
<thead>
<tr>
<td>Car</td>
<td>Color</td>
<td>Count</td>
</tr>
</thead>
<tbody>
<?php
foreach($cars as $car):
?>
<tr>
<td><?= $car ?></td>
<td><?= generateRandomColor() ?></td>
<td><?= generateRandomQuantity() ?></td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
<?php
endif;
?>
</body>
</html>