本文整理汇总了PHP中Cake\Collection\Collection::reject方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::reject方法的具体用法?PHP Collection::reject怎么用?PHP Collection::reject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Collection\Collection
的用法示例。
在下文中一共展示了Collection::reject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReject
/**
* Tests reject
*
* @return void
*/
public function testReject()
{
$items = ['a' => 1, 'b' => 2, 'c' => 3];
$collection = new Collection($items);
$result = $collection->reject(function ($v, $k, $items) use($collection) {
$this->assertSame($collection->getInnerIterator(), $items);
return $v > 2;
});
$this->assertEquals(['a' => 1, 'b' => 2], iterator_to_array($result));
$this->assertInstanceOf('Cake\\Collection\\Collection', $result);
}
示例2: testReject
/**
* Tests reject
*
* @return void
*/
public function testReject()
{
$this->assertFalse(defined('HHVM_VERSION'), 'Broken on HHVM');
$items = ['a' => 1, 'b' => 2, 'c' => 3];
$collection = new Collection($items);
$result = $collection->reject(function ($v, $k, $items) use($collection) {
$this->assertSame($collection, $items);
return $v > 2;
});
$this->assertEquals(['a' => 1, 'b' => 2], iterator_to_array($result));
$this->assertInstanceOf('\\Cake\\Collection\\Collection', $result);
}
示例3: getOpponent
public function getOpponent($user_id)
{
$gm_collection = new Collection($this->game_memberships);
$opponents = $gm_collection->reject(function ($gm, $key) use($user_id) {
return $user_id == $gm->member_id;
});
if (!($opponent = $opponents->first())) {
return false;
}
if (!($opponent->member or $opponent->temp_member)) {
return false;
}
return $opponent;
}