Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class View
- {
- //definition
- private $id;
- private $name;
- private $email;
- /*
- * Constructor
- */
- public function __construct($id, $name, $email)
- {
- $this->id = $id;
- $this->name = $name;
- $this->email = $email;
- }
- /*
- * get ID
- */
- public function getId()
- {
- return $this->id;
- }
- /*
- * get Name
- */
- public function getName()
- {
- return $this->name;
- }
- /*
- * get Email
- */
- public function getEmail()
- {
- return $this->email;
- }
- }
- // New View List Class which extends arrayObject in PHP
- class ViewList extends ArrayObject
- {
- /*
- * a public function to return data
- */
- public function displayAsTable() // or you could even override the __toString if you want.
- {
- $sOutput = '<table border="1"><tbody>';
- foreach ($this AS $user)
- {
- $sOutput .= sprintf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>',
- $user->getId(),
- $user->getName(),
- $user->getEmail()
- );
- }
- $sOutput .= print '</tbody></table>';
- return $sOutput;
- }
- /*
- * return data to string
- */
- public function __toString()
- {
- return $this->displayAsTable();
- }
- }
- /*
- * data(s)
- */
- $data = new ViewList();
- $data[] = new View(1, 'Selim Reza', '[email protected]');
- $data[] = new View(2, 'Half Way', '[email protected]');
- /*
- * final output
- */
- print $data;
Advertisement
Add Comment
Please, Sign In to add comment