本文整理汇总了PHP中Illuminate\Support\Collection::max方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::max方法的具体用法?PHP Collection::max怎么用?PHP Collection::max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::max方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGettingMaxItemsFromCollection
public function testGettingMaxItemsFromCollection()
{
$c = new Collection([(object) ['foo' => 10], (object) ['foo' => 20]]);
$this->assertEquals(20, $c->max('foo'));
$c = new Collection([['foo' => 10], ['foo' => 20]]);
$this->assertEquals(20, $c->max('foo'));
$c = new Collection([1, 2, 3, 4, 5]);
$this->assertEquals(5, $c->max());
$c = new Collection();
$this->assertNull($c->max());
}
示例2: generateSuffix
/**
* Generate a unique suffix for the given slug (and list of existing, "similar" slugs.
*
* @param string $slug
* @param string $separator
* @param \Illuminate\Support\Collection $list
* @return string
*/
protected function generateSuffix($slug, $separator, Collection $list)
{
$len = strlen($slug . $separator);
// If the slug already exists, but belongs to
// our model, return the current suffix.
if ($list->search($slug) === $this->model->getKey()) {
$suffix = explode($separator, $slug);
return end($suffix);
}
$list->transform(function ($value, $key) use($len) {
return intval(substr($value, $len));
});
// find the highest value and return one greater.
return $list->max() + 1;
}