-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.php
49 lines (47 loc) · 1.63 KB
/
table.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
<?php
// Require array $teams
require_once __DIR__ . "/resources/data.php";
// Create array with table headings
//$headings = ['team'=>'Team', 'nickname'=>'Nickname', 'city'=>'City', 'league'=>'League', 'last-time-champions'=>'Last time champion', 'URL'];
$headings = ['Team', 'Nickname', 'City', 'League', 'Last time champions', 'URL'];
?>
<table>
<thead>
<tr>
<?php
// Create first row of table with column headings from $headings array
foreach ($headings as $heading) :
?>
<th><?= $heading; ?></th>
<?php
endforeach;
?>
</tr>
</thead>
<tbody>
<?php
// Loop through secondary array, create one table row for each team
foreach ($teams as $teamname => $team) :
?>
<tr>
<!-- Use current key value to get team names -->
<td><?= $teamname; ?></td>
<td>
<?php
// Check if current team has key 'nickname', if so print nickname, else <td> will be empty
if (array_key_exists('nickname', $team)) {
echo $team['nickname'];
}
?>
</td>
<!-- Get rest of values from $team array -->
<td><?= $team['city']; ?></td>
<td><?= $team['league']; ?></td>
<td><?= $team['last-time-champions']; ?></td>
<td><a href="<?= $team['url']; ?>"><?= $team['url']; ?></a></td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>