php class Country public name public population public ccity function

 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
<?php
class Country {
public $name;
public $population;
public $ccity;
function Country($name, $population, $ccity){
$this->name = $name;
$this->population = $population;
$this->ccity = $ccity;
}
function show(){
echo "<div class = 'wrapper'>
<table>
<tr>
<td>
Name:
</td>
<td>
".$this->name."
</td>
</tr>
<tr>
<td>
Population:
</td>
<td>
".$this->population."
</td>
</tr>
<tr>
<td>
Capital city:
</td>
<td>
".$this->ccity."
</td>
</tr>
</table>
<hr>
</div>";
}
}
?>
<style type="text/css">
.wrapper{
width: 200px;
margin: 0 auto;
text-align:center;
}
</style>
<div class = 'wrapper'>
<a href='Task1.php'>prev</a>
| Task 2 |
<a href='Task3.php'>next</a><hr>
</div>
<?php
$countrys = array("Ukraine","German","Great Britan","Russia");
$populations = array(35000000, 30000000, 31000000, 120000000);
$ccitys = array("Kyiv","Berlin","London","Moscow");
$obj = array();
for ($i = 0; $i < sizeof($countrys); $i++) {
$obj[$i] = new Country($countrys[$i], $populations[$i], $ccitys[$i]);
$obj[$i]->show();
}
?>