本文整理汇总了PHP中Collection::first方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::first方法的具体用法?PHP Collection::first怎么用?PHP Collection::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection::first方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFirst
/**
* @test Collection::first()
*/
public function testFirst()
{
$this->buildEnvironment();
$result = $this->collection->first();
$expect = $this->source['a1'];
$this->assertEquals($expect, $result);
}
示例2: _dumpCollection
public static function _dumpCollection(Collection $collection)
{
if (is_object($collection->first()) and $collection->first() instanceof Model) {
$output = "<span><strong>Collection of " . get_class($collection->first()) . " Models</strong></span>\n";
} else {
$output = "<span><strong>Collection object:</strong></span>\n";
}
foreach ($collection as $key => $value) {
$output .= " " . \Automatorm\Orm\Dump::format($key, $value);
}
return $output;
}
示例3: testPopPushPutShiftUnshiftInject
public function testPopPushPutShiftUnshiftInject()
{
// pop
$_3 = $this->collection->pop();
$this->assertEquals($this->_3, $_3);
$this->assertEquals($this->_2, $this->collection->last());
$this->assertEquals(3, $this->collection->count());
// push
$this->collection->push($_3);
$this->assertEquals($this->_3, $this->collection->last());
// put
$this->collection->put(2, 'test');
$this->assertEquals('test', $this->collection->get(2));
// shift
$_0 = $this->collection->shift();
$this->assertEquals($this->_0, $_0);
$this->assertEquals($this->_1, $this->collection->first());
$this->assertEquals(3, $this->collection->count());
// unshift
$this->collection->unshift($_0);
$this->assertEquals($this->_0, $this->collection->first());
// inject
$this->collection->inject(2, 'test2');
$this->assertEquals('test2', $this->collection->get(2));
$this->assertEquals(5, $this->collection->count());
}
示例4: tags
public function tags()
{
$collection = Collection::first();
// Get all tags
$tags = $collection->getTags();
// Find how many are in the specified decks
foreach ($tags as $tag) {
$q = DB::table('cards')->select(DB::raw('count() as cards_count'), DB::raw('avg(ivl) as average_interval'))->join('notes', 'cards.nid', '=', 'notes.id')->where('tags', 'like', '%' . $tag . '%')->whereIn('did', $this->myDecks())->first();
if ((int) $q->cards_count === 0) {
continue;
}
$results[$tag] = ['tag' => $tag, 'count' => (int) $q->cards_count, 'value' => round($q->average_interval, 1)];
}
return Response::json($results);
}
示例5: first
/** {@inheritdoc} */
public function first()
{
$this->initialize();
return $this->coll->first();
}
示例6: firstFile
/**
* Returns the first file of the Gist.
*
* @return GistFile
*/
public function firstFile()
{
return $this->files->first();
}
示例7: testFirst
public function testFirst()
{
$el = $this->collection->first();
$this->assertEquals($this->_0, $el);
}
示例8: visibilitiesColInfo
/**
* Same as visibilityInfo, but for visibility collections
*/
public static function visibilitiesColInfo(Collection $visibilities)
{
if ($visibilities->count() == 0) {
return array('green', "Tout le monde");
} elseif ($visibilities->count() == 1) {
return self::visibilityInfo($visibilities->first());
}
$textes = array();
foreach ($visibilities as $v) {
list($color, $text) = self::visibilityInfo($v);
$textes[] = $text;
}
return array('grey', implode(', ', $textes));
}
示例9: testFirst
public function testFirst()
{
$collection = new Collection(['a' => 'c', 'b' => 'd']);
$this->assertSame('c', $collection->first());
}