当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::indexBy方法代码示例

本文整理汇总了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;
 }
开发者ID:abf6ug,项目名称:statbro,代码行数:23,代码来源:Game.php

示例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));
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:13,代码来源:CollectionTest.php

示例3: _indexBy

 protected function _indexBy($game_memberships, $by = 'id')
 {
     $gmCollection = new Collection($game_memberships);
     return $gmCollection->indexBy($by);
 }
开发者ID:abf6ug,项目名称:statbro,代码行数:5,代码来源:GamesController.php


注:本文中的Cake\Collection\Collection::indexBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。