3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <table style="width: 50%"> <tr> <td><a href="?order=name">Nazov</a></td> <td><a href="?order=model">Model</a></td> <td><a href="?">Naspat</a></td> </tr> <?php /** * Created by PhpStorm. * User: maruna2 * Date: 5.11.2015 * Time: 18:31 */ class Auto { private $nazov; private $model; function __construct($nazov,$model){ $this->model=$model; $this->nazov=$nazov; } function getNazov() { return $this->nazov; } function getModel() { return $this->model; } } function compare($a,$b) { if(isset($_GET["order"])) { if($_GET["order"]=="name") return strcmp($a->getNazov(),$b->getNazov()); if($_GET["order"]=="model") return strcmp($a->getModel(),$b->getModel()); } return 0; } $pole; $pole[] = new Auto("Ford","Escort"); $pole[] = new Auto("Ford","Focus"); $pole[] = new Auto("Skoda","Fabia"); $pole[] = new Auto("Volkswagen","Golf"); $pole[] = new Auto("Chevrolet","Corvette"); usort($pole, "compare"); ?> <?php foreach($pole as $auto) {?> <tr> <td><?php echo $auto->getNazov()?></td> <td><?php echo $auto->getModel()?></td> </tr> <?php } ?> </table> </body> </html>
based on KqMJM
Output for 7.0.0 - 7.2.0
<html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <table style="width: 50%"> <tr> <td><a href="?order=name">Nazov</a></td> <td><a href="?order=model">Model</a></td> <td><a href="?">Naspat</a></td> </tr> <tr> <td>Ford</td> <td>Escort</td> </tr> <tr> <td>Ford</td> <td>Focus</td> </tr> <tr> <td>Skoda</td> <td>Fabia</td> </tr> <tr> <td>Volkswagen</td> <td>Golf</td> </tr> <tr> <td>Chevrolet</td> <td>Corvette</td> </tr> </table> </body> </html>
Output for 5.5.0 - 5.6.28
<html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <table style="width: 50%"> <tr> <td><a href="?order=name">Nazov</a></td> <td><a href="?order=model">Model</a></td> <td><a href="?">Naspat</a></td> </tr> <tr> <td>Chevrolet</td> <td>Corvette</td> </tr> <tr> <td>Volkswagen</td> <td>Golf</td> </tr> <tr> <td>Skoda</td> <td>Fabia</td> </tr> <tr> <td>Ford</td> <td>Focus</td> </tr> <tr> <td>Ford</td> <td>Escort</td> </tr> </table> </body> </html>