3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Osoba{ private $meno; private $priezvisko; private $vek; function __construct($meno,$priezvisko,$vek){ $this->meno = $meno; $this->priezvisko = $priezvisko; $this->vek = $vek; } function get_meno(){ return $this->meno; } function get_priezvisko(){ return $this->priezvisko; } function get_vek(){ return $this->vek; } } function vytvor(){ $a= new Osoba("J","B",30); $b= new Osoba("V","E",12); $c= new Osoba("S","N",78); $d= new Osoba("Q","W",6); $pole=array($a,$b,$c,$d); return $pole; } function vytvorTabulku(){ vytvor(); $table .= '<table>'; foreach($pole as $osoba){ $table .= '<tr>'; $table .= '<td>'.$osoba->get_meno().'</td><td>'.$osoba->get_priezvisko().'</td><td>'.$osoba->get_vek().'</td>'; $table .= '</tr>'; } $table .= '</table>'; return $table; } ?> <!DOCTYPE html> <html> <head> <title>cviko</title> </head> <body> <table> <tr> <td><a href="?order=name">meno</a></td> <td><a href="?order=priezvisko">priezvisko</a></td> <td><a href="?order=vek">vek</a></td> </tr> <?php echo vytvorTabulku(); ?> </table> </body> </html>
based on 0HbuE
Output for 5.3.19 - 7.2.0
<!DOCTYPE html> <html> <head> <title>cviko</title> </head> <body> <table> <tr> <td><a href="?order=name">meno</a></td> <td><a href="?order=priezvisko">priezvisko</a></td> <td><a href="?order=vek">vek</a></td> </tr> Notice: Undefined variable: table in /in/o3GO5 on line 36 Notice: Undefined variable: pole in /in/o3GO5 on line 37 Warning: Invalid argument supplied for foreach() in /in/o3GO5 on line 37 <table></table> </table> </body> </html>