当前位置: 首页>>代码示例>>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;未经允许,请勿转载。