3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Box { private $x; private $y; private $z; public function __construct($x, $y, $z) { $this->x = $x; $this->y = $y; $this->z = $z; } public function getX() { return $this->x; } public function getY() { return $this->y; } public function getZ() { return $this->z; } public function __toString() { return "[{$this->x}, {$this->y}, {$this->z}]"; } public function maxRozmer() { return max([$this->x, $this->y, $this->z]); } } //find max rozmer function cmp(Box $a, Box $b) : int { if($a->maxRozmer() == $b->maxRozmer()) { return 0; } return ($a->maxRozmer() > $b->maxRozmer()) ? -1 : 1; } $boxes = [ new Box(7,7,4), new Box(101,1,2), new Box(5,20,1), ]; $result = usort($boxes, "cmp"); print_r($result); print_r($boxes);

preferences:
53.47 ms | 402 KiB | 5 Q