-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray3.php
40 lines (25 loc) · 956 Bytes
/
array3.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
<?php
$ceu = array( "Italy"=>"Rome",
"Luxembourg"=>"Luxembourg",
"Belgium"=> "Brussels",
"Denmark"=>"Copenhagen", "Finland"=>"Helsinki", "France" => "Paris",
"Slovakia"=>"Bratislava", "Slovenia"=>"Ljubljana", "Germany" => "Berlin",
"Greece" => "Athens", "Ireland"=>"Dublin", "Netherlands"=>"Amsterdam", "Portugal"=>"Lisbon",
"Spain"=>"Madrid", "Sweden"=>"Stockholm", "United Kingdom"=>"London", "Cyprus"=>"Nicosia",
"Lithuania"=>"Vilnius",
"Czech Republic"=>"Prague",
"Estonia"=>"Tallin", "Hungary"=>"Budapest",
"Latvia"=>"Riga", "Malta"=>"Valetta", "Austria" => "Vienna",
"Poland"=>"Warsaw") ;
echo '<pre>';
ksort($ceu);
foreach ($ceu as $country=>$capital) {
echo "The capital of $country is $capital <br />";
}
// alternate approach to print using array_walk, calls callback function with key, value
array_walk($ceu, "print_result");
function print_result($v, $k)
{
echo "The capital of $k is $v <br />";
}
?>