FOF30\Model\DataModel\Collection::max PHP Метод

max() публичный Метод

Get the max value of a given key.
public max ( string $key ) : mixed
$key string
Результат mixed
    public function max($key)
    {
        return $this->reduce(function ($result, $item) use($key) {
            return is_null($result) || $item->{$key} > $result ? $item->{$key} : $result;
        });
    }

Usage Example

Пример #1
0
 /**
  * @group           DataModel
  * @group           CollectionMax
  * @covers          FOF30\Model\DataModel\Collection::max
  */
 public function testMax()
 {
     $items = $this->buildCollection();
     $collection = new Collection($items);
     $result = $collection->max('foftest_bare_id');
     // Let's get the maximum value directly from the db
     $db = \JFactory::getDbo();
     $query = $db->getQuery(true)->select('MAX(foftest_bare_id)')->from('#__foftest_bares');
     $max = $db->setQuery($query)->loadResult();
     $this->assertEquals($max, $result, 'Collection::max Failed to return highest value');
 }