本文整理汇总了PHP中Cake\Collection\Collection::firstMatch方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::firstMatch方法的具体用法?PHP Collection::firstMatch怎么用?PHP Collection::firstMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Collection\Collection
的用法示例。
在下文中一共展示了Collection::firstMatch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFirstMatch
/**
* Tests firstMatch
*
* @return void
*/
public function testFirstMatch()
{
$items = [['id' => 1, 'name' => 'foo', 'thing' => ['parent_id' => 10]], ['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]], ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]]];
$collection = new Collection($items);
$matched = $collection->firstMatch(['thing.parent_id' => 10]);
$this->assertEquals(['id' => 1, 'name' => 'foo', 'thing' => ['parent_id' => 10]], $matched);
$matched = $collection->firstMatch(['thing.parent_id' => 10, 'name' => 'baz']);
$this->assertEquals(['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]], $matched);
}
示例2: testFirstMatch
/**
* Tests firstMatch
*
* @return void
*/
public function testFirstMatch()
{
$this->assertFalse(defined('HHVM_VERSION'), 'Broken on HHVM');
$items = [['id' => 1, 'name' => 'foo', 'thing' => ['parent_id' => 10]], ['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]], ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]]];
$collection = new Collection($items);
$matched = $collection->firstMatch(['thing.parent_id' => 10]);
$this->assertEquals(['id' => 1, 'name' => 'foo', 'thing' => ['parent_id' => 10]], $matched);
$matched = $collection->firstMatch(['thing.parent_id' => 10, 'name' => 'baz']);
$this->assertEquals(['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]], $matched);
}
示例3: getCurrent
public function getCurrent($user_id)
{
$gm_collection = new Collection($this->game_memberships);
$current = $gm_collection->firstMatch(['member_id' => $user_id]);
if (!$current->member) {
return false;
}
return $current;
}