-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1. PHP-HTML challenge.php
More file actions
41 lines (33 loc) · 1.03 KB
/
1. PHP-HTML challenge.php
File metadata and controls
41 lines (33 loc) · 1.03 KB
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
<?php
class Person extends ArrayObject {
// set Key, Value to the instance
public function __set($name, $val) {
$this[$name] = $val;
}
public function displayAsTable() {
//Create iterator from parent class
$iterator = $this->getIterator();
$table = '<table style="border-collapse: collapse">';
$table .= '<tbody>';
//iterate through the iterator
while($iterator->valid()) {
$table .= '<tr>';
$table .= '<th style="padding: 5px; border: 1px solid #ddd">' . $iterator->key() . '</th>';
$table .= '<td style="padding: 5px; border: 1px solid #ddd">' . $iterator->current() . '</td>';
$table .= '</tr>';
$iterator->next();
}
$table .= '</tbody>';
$table .= '</table>';
return $table;
}
}
// make instance of Person class which is inherited from ArrayObject class
$obj = new Person();
//set some keys & values
$obj->Name = 'Md. Asadujjaman Nur';
$obj->Email = 'asadece2k10@gmail.com';
$obj->Mobile = '+8801740227805';
// display the data
echo $obj->displayAsTable();
?>