3v4l.org

run code in 300+ PHP versions simultaneously
<?php function max_by($collection, $property) { $plucked = array_map(function ($item) use ($property) { return $item->$property; }, $collection); return max($plucked); } class A { function __construct($u,$v) { $this->u = $u; $this->v = $v; } } $array = [ new A(1,3), new A(2,2), new A(3,1) ]; $a = max_by($array, 'u'); var_dump($a);

preferences:
40.89 ms | 402 KiB | 5 Q