assignment4 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of assignment4.php

  1. <?php
  2. class Persona {
  3.         public $name;
  4.         public $arcana;
  5.         public $level;
  6.     
  7.     function __construct($x, $y, $z){
  8.         $this->name = $x;
  9.         $this->arcana = $y;
  10.         $this->level = $z;
  11.     }
  12.     
  13.     function get_name(){
  14.         return $this->name;
  15.     }
  16.     
  17.     function get_arcana(){
  18.         return $this->arcana;
  19.     }
  20.     
  21.     function get_level(){
  22.         return $this->level;
  23.     }
  24.  }
  25.  
  26. $Ippon_Datara = new Persona("Ippon-Datara", "Hanged", 13);
  27. $Thunderbird = new Persona("Thunderbird", "Sun", 35);
  28. $Fafnir = new Persona("Fafnir", "Hermit", 86);
  29.  
  30. $myArray = array();
  31. array_push($myArray, $Ippon_Datara, $Thunderbird, $Fafnir);
  32.  
  33. $output = "";
  34.  
  35. $output .= '<TABLE border="2">';
  36. $output .= '<tr>';
  37. $output .= '<th>' . "Name" . '</th>';
  38. $output .= '<th>' . "Arcana" . '</th>';
  39. $output .= '<th>' . "Level"  . '</th>';
  40. $output .= '</tr>';
  41.  
  42. foreach($myArray as $obj){
  43.     $output .= "<tr>";
  44.     $output .= "<td>" . $obj->get_name() . "</td>";
  45.     $output .= "<td>" . $obj->get_arcana() . "</td>";
  46.     $output .= "<td>" . $obj->get_level() . "</td>";
  47.     $output .= "</tr>";
  48. }
  49.  
  50. echo $output;
  51.  
File Description
  • assignment4
  • PHP Code
  • 09 Jul-2021
  • 1.09 Kb
You can Share it: