3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Customer { public $score; public function __construct($score) { $this->score = $score; } } $customers = []; $customers[] = new Customer(13); $customers[] = new Customer(11); $customers[] = new Customer(14); $customers[] = new Customer(10); $customers[] = new Customer(12.5); usort($customers, function($a, $b) { var_dump($b->score, $a->score, $b->score - $a->score); return $b->score - $a->score; }); var_dump($customers);
based on BOdr3
Output for 7.0.0 - 7.2.0
int(11) int(13) int(-2) int(14) int(11) int(3) int(14) int(13) int(1) int(10) int(11) int(-1) float(12.5) int(10) float(2.5) float(12.5) int(11) float(1.5) float(12.5) int(13) float(-0.5) array(5) { [0]=> object(Customer)#3 (1) { ["score"]=> int(14) } [1]=> object(Customer)#1 (1) { ["score"]=> int(13) } [2]=> object(Customer)#5 (1) { ["score"]=> float(12.5) } [3]=> object(Customer)#2 (1) { ["score"]=> int(11) } [4]=> object(Customer)#4 (1) { ["score"]=> int(10) } }
Output for 5.4.11 - 5.6.28
int(11) int(14) int(-3) int(14) float(12.5) float(1.5) int(14) int(10) int(4) int(14) int(13) int(1) int(14) int(11) int(3) int(11) int(13) int(-2) int(13) float(12.5) float(0.5) int(13) int(10) int(3) int(10) int(11) int(-1) array(5) { [0]=> object(Customer)#3 (1) { ["score"]=> int(14) } [1]=> object(Customer)#5 (1) { ["score"]=> float(12.5) } [2]=> object(Customer)#1 (1) { ["score"]=> int(13) } [3]=> object(Customer)#2 (1) { ["score"]=> int(11) } [4]=> object(Customer)#4 (1) { ["score"]=> int(10) } }
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/VfZ1W on line 10
Process exited with code 255.