本文整理匯總了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);
}