當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Arrays::groupBy方法代碼示例

本文整理匯總了PHP中Ouzo\Utilities\Arrays::groupBy方法的典型用法代碼示例。如果您正苦於以下問題:PHP Arrays::groupBy方法的具體用法?PHP Arrays::groupBy怎麽用?PHP Arrays::groupBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Ouzo\Utilities\Arrays的用法示例。


在下文中一共展示了Arrays::groupBy方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getClosedByRoundForCricket

 public function getClosedByRoundForCricket()
 {
     $hits = Hit::join('game_user->user')->where(['game_user_id' => $this->id])->order('hits.id asc')->fetchAll();
     $byRound = Arrays::groupBy($hits, Functions::extract()->round);
     $closedInRound = [];
     $closed = [15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 25 => 0];
     foreach ($byRound as $round => $hits) {
         $closedInCurrentRound = 0;
         foreach ($hits as $hit) {
             if (isset($closed[$hit->field])) {
                 $closedField = min($hit->multiplier, 3 - $closed[$hit->field]);
                 $closedInCurrentRound += $closedField;
                 $closed[$hit->field] += $closedField;
             }
         }
         $closedInRound[$round] = $closedInCurrentRound;
     }
     return $closedInRound;
 }
開發者ID:thuliumcc,項目名稱:dartboard,代碼行數:19,代碼來源:GameUser.php

示例2: groupBy

 public function groupBy($selector)
 {
     $this->_array = Arrays::groupBy($this->_array, $selector);
     return $this;
 }
開發者ID:letsdrink,項目名稱:ouzo,代碼行數:5,代碼來源:FluentArray.php

示例3: _loadRelationObjectsIndexedById

 private function _loadRelationObjectsIndexedById($localKeys)
 {
     $relationObject = $this->_relation->getRelationModelObject();
     $relationObjects = $relationObject::where(array($this->_relation->getForeignKey() => $localKeys))->where($this->_relation->getCondition())->order($this->_relation->getOrder())->fetchAll();
     return Arrays::groupBy($relationObjects, Functions::extractField($this->_relation->getForeignKey()));
 }
開發者ID:letsdrink,項目名稱:ouzo,代碼行數:6,代碼來源:RelationFetcher.php

示例4: shouldGroupByAndSort

 /**
  * @test
  */
 public function shouldGroupByAndSort()
 {
     //given
     $product1 = new Product(array('name' => 'a', 'description' => '1', 'id_category' => '1'));
     $product2 = new Product(array('name' => 'b', 'description' => '2', 'id_category' => '2'));
     $product3 = new Product(array('name' => 'c', 'description' => '2', 'id_category' => '1'));
     $array = array($product1, $product2, $product3);
     //when
     $grouped = Arrays::groupBy($array, Functions::extractField('description'), 'id_category');
     //then
     $this->assertEquals(array('1' => array($product1), '2' => array($product3, $product2)), $grouped);
 }
開發者ID:letsdrink,項目名稱:ouzo,代碼行數:15,代碼來源:ArraysTest.php


注:本文中的Ouzo\Utilities\Arrays::groupBy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。