當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。