Advertisement
Yousuf1791

Book-page-80

May 15th, 2022
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. <?php
  2.  
  3. class Consultant{
  4.     private $name = "";
  5.     private $role = "";
  6.  
  7.     public function __construct($name,$role){
  8.         $this->name = $name;
  9.         $this->role = $role;
  10.     }
  11.  
  12.     public function showRoles(){
  13.         echo "Name : ". $this->name . "<br>";
  14.         echo "Role : ". $this->role . "<br>";
  15.     }
  16. }
  17.  
  18. $data = [];
  19.  
  20. $r1 = new Consultant("Yousuf", "CEO");
  21. $data[] = $r1;
  22.  
  23. $r2 = new Consultant("Emran", "Managing Director");
  24. $data[] = $r2;
  25.  
  26. $r3 = new Consultant("Shohag", "Assistant Manager");
  27. $data[] = $r3;
  28.  
  29. $i = 1;
  30.  
  31. foreach ($data as $value) {
  32.     echo "Role # ". $i . ":<br>";
  33.     $value->showRoles();
  34.     $i++;
  35. }
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement