-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnack5.php
89 lines (75 loc) · 1.95 KB
/
snack5.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
80
81
82
83
84
85
86
87
88
89
<!--
Snack 5
Utilizzare questo array: https://pastebin.com/CkX3680A. Stampiamo il nostro array mettendo gli insegnanti in un rettangolo grigio e i PM in un rettangolo verde. -->
<?php
$db = [
'teachers' => [
[
'name' => 'Michele',
'lastname' => 'Papagni'
],
[
'name' => 'Fabio',
'lastname' => 'Forghieri'
]
],
'pm' => [
[
'name' => 'Roberto',
'lastname' => 'Marazzini'
],
[
'name' => 'Federico',
'lastname' => 'Pellegrini'
]
]
];
$keys = array_keys($db);
// var_dump($keys);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
<title>Document</title>
</head>
<style>
body {
font-family: 'Roboto', sans-serif;
}
.box {
width: max-content;
height: 200px;
margin: 0 auto;
}
.pm,
.teachers {
padding: 10px 20px;
margin: 10px;
}
.pm {
background-color: lightgreen;
}
.teachers {
background-color: lightgrey;
}
</style>
<body>
<div class="box">
<?php for ($i = 0; $i < count($db); $i++) {
$currentItem = $db[$keys[$i]]; ?>
<div class="<?php echo $keys[$i] ?>">
<?= $keys[$i] ?>:
<?php for ($j = 0; $j < count($currentItem); $j++) { ?>
<li> <?php echo $currentItem[$j]['name'] . ' ' . $currentItem[$j]['lastname']; ?></li>
<?php } ?>
</div>
<?php } ?>
</div>
</body>
</html>