- var_dump: documentation ( source)
- array_reduce: documentation ( source)
<?php
class Foo
{
private $a;
public function __construct($a)
{
$this->a = (int) $a;
}
public static function maxA(array $fooList)
{
return array_reduce($fooList, function($carry, self $item) {
return ($carry == null || $item->a > $carry->a) ? $item : $carry;
});
}
}
$fooList = [
new Foo(1),
new Foo(5),
new Foo(2),
];
var_dump(Foo::maxA($fooList));