-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexo2.php
62 lines (52 loc) · 1.58 KB
/
exo2.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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=, initial-scale=1.0">
<title>PHP PARTIE 2 : EXO 2</title>
</head>
<body>
<h1>EXO 2</h1>
<p>
Soit le tableau suivant :
$capitales = array
("France"=>"Paris","Allemagne"=>"Berlin","USA"=>"Washington","Italie"=>"Rome");
Réaliser un algorithme permettant d’afficher le tableau HTML suivant (notez que le nom du pays
s’affichera en majuscule et que le tableau est trié par ordre alphabétique du nom de pays) grâce à
une fonction personnalisée.
Vous devrez appeler la fonction comme suit : afficherTableHTML($capitales);
</p>
<br>
<hr>
<h2><u>SOLUTION DES EXERCICES</u>:</h2>
</body>
<style>
table,th,td{
border: solid 1px black;
padding:10px;
}
</style>
<?php
$capitales = ['France' => 'Paris',
'Allemagne' => 'Berlin',
'USA' => 'NewYork',
'Italie' => 'Rome', ];
function afficherTableHTML($tableau)
{
ksort($tableau); // ksort = tableau ordre croissant
$tab = '<table>
<thead>
<tr><th>Pays</th>
<th>Capitale</th></tr>
</thead><tbody>';
foreach ($tableau as $pays => $capital) {
$tab .= '<tr><td>';
$tab .= mb_strtoupper($pays);
$tab .= ' </td>';
$tab .= " <td> $capital </td></tr>";
}
$tab .= '</tbody></table>';
return $tab;
}
echo afficherTableHTML($capitales);