-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27.php
More file actions
56 lines (48 loc) · 1.34 KB
/
27.php
File metadata and controls
56 lines (48 loc) · 1.34 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>27</title>
<style>
input[type='text'] {
width: 30px;
}
</style>
</head>
<body>
<form action="" method="post">
<input type="text" name='rows'>
<input type="text" name='cols'>
<input type="submit" name="sub" value="Сгенерировать">
</form>
</body>
</html>
<?php
if (isset($_POST['sub'])) {
if (is_numeric($_POST['rows']) && is_numeric($_POST['cols'])) {
$rows = $_POST['rows'];
$cols = $_POST['cols'];
if ($rows > 100 || $cols > 100) {
echo 'Ваш компьютер не настолько крут';
} else {
create_table($rows, $cols);
}
} else {
echo 'Задайте правильно количество строк и столбцов';
}
}
function create_table($rw, $cl)
{
$colors = ['red', 'yellow', 'blue', 'gray', 'maroon', 'brown', 'green'];
echo '<table>';
for ($i = 0; $i < $rw; $i++) {
echo '<tr>';
for ($j = 0; $j < $cl; $j++) {
$random_color = rand(0, count($colors) - 1);
echo '<td style = background-color:' . $colors[$random_color] . '>' . rand() . '</td>';
}
echo '</tr>';
}
echo '</table>';
}
?>