-
Notifications
You must be signed in to change notification settings - Fork 0
/
exo2.php
44 lines (34 loc) · 1.25 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
<h2>Exercice 2</h2>
<p>
Soit le tableau suivant :<br>
$capitales = array<br>
("France"=>"Paris","Allemagne"=>"Berlin","USA"=>"Washington","Italie"=>"Rome");<br>
Réaliser un algorithme permettant de les afficher sous forme de tableau HTML
avec le nom du pays affiché en majuscules et triés par ordre alphabétique grâce
à une fonction personnalisée.<br>
</p>
<?php
$capitales = array("France" => "Paris", "Allemagne" => "Berlin", "USA" => "Washington", "Italie" => "Rome");
ksort($capitales);
afficherTableHTML($capitales);
function afficherTableHTML($array) {
echo "<table border=1><th>Pays </th><th>Capitale </th>";
foreach ($array as $key => $value) {
echo "<tr><td>". strtoupper($key) ."</td><td>". $value."</td></tr>";
}
echo "</table>";
}
/*
$capitals = array("" => "", "" => "");
function afficherTableHTML($capitals) {
ksort($capitals);
echo "<pre>";
print_r(array_change_key_case($capitals, CASE_UPPER));
echo "</pre>";
}
afficherTableHTML($capitales);
foreach ($this->chambres as $chambre) {
$result .= "Chambre ". $chambre->getnumChambre(). "
". $chambre->getPrixNuit(). "€ ". $chambre->getWifi(). " ".$chambre->getDisponible() ."<br>";
} return $result;
*/