本文整理汇总了PHP中Cake\Collection\Collection::indexBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::indexBy方法的具体用法?PHP Collection::indexBy怎么用?PHP Collection::indexBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Collection\Collection
的用法示例。
在下文中一共展示了Collection::indexBy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getLosers
protected function _getLosers()
{
// $gameMembershipsCollection = new Collection($this->game_memberships);
// $victor_member = $gameMembershipsCollection->indexBy('id')->max('points');
//
// $victor['full_name'] = Hash::get($victor_member, 'member.full_name');
// $victor['id'] = Hash::get($victor_member, 'member.id');
$gm_collection = new Collection($this->game_memberships);
$victor = $gm_collection->indexBy('id')->max('points');
$victor_id = $victor->generic_member->id;
$losers = $gm_collection->filter(function ($gm, $key) use($victor_id) {
return $victor_id != $gm->generic_member->id;
});
// if(!$loser = $losers->first())
// return false;
// if(!($loser->member or $loser->temp_member))
// return false;
$losers_array = [];
foreach ($losers as $loser) {
array_push($losers_array, $loser);
}
return $losers_array;
}
示例2: testIndexByDeep
/**
* Tests indexBy with a deep property
*
* @return void
*/
public function testIndexByDeep()
{
$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);
$grouped = $collection->indexBy('thing.parent_id');
$expected = [10 => ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]], 11 => ['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]]];
$this->assertEquals($expected, iterator_to_array($grouped));
}
示例3: _indexBy
protected function _indexBy($game_memberships, $by = 'id')
{
$gmCollection = new Collection($game_memberships);
return $gmCollection->indexBy($by);
}