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


PHP Collection::fetch方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Collection::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::fetch方法的具体用法?PHP Collection::fetch怎么用?PHP Collection::fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Collection的用法示例。


在下文中一共展示了Collection::fetch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: lists

 /**
  * Get an array with the values of a given column.
  *
  * @param  string  $column
  * @param  string  $key
  * @return array
  */
 public function lists($column, $key = null)
 {
     $columns = $this->getListSelect($column, $key);
     // First we will just get all of the column values for the record result set
     // then we can associate those values with the column if it was specified
     // otherwise we can just give these values back without a specific key.
     $res = $this->get($columns);
     $results = new Collection($res->getData());
     $values = $results->fetch($columns[0])->all();
     // If a key was specified and we have results, we will go ahead and combine
     // the values with the keys of all of the records so that the values can
     // be accessed by the key of the rows instead of simply being numeric.
     if (!is_null($key) && count($results) > 0) {
         $keys = $results->fetch($key)->all();
         return array_combine($keys, $values);
     }
     return $values;
 }
开发者ID:sgpatil,项目名称:orientdb,代码行数:25,代码来源:Builder.php

示例2: scopeListsNested

 /**
  * Gets an array with values of a given column. Values are indented according to their depth.
  * @param  string $column Array values
  * @param  string $key    Array keys
  * @param  string $indent Character to indent depth
  * @return array
  */
 public function scopeListsNested($query, $column, $key = null, $indent = '   ')
 {
     $columns = [$this->getDepthColumnName(), $column];
     if ($key !== null) {
         $columns[] = $key;
     }
     $results = new Collection($query->getQuery()->get($columns));
     $values = $results->fetch($columns[1])->all();
     $indentation = $results->fetch($columns[0])->all();
     foreach ($values as $_key => $value) {
         $values[$_key] = str_repeat($indent, $indentation[$_key]) . $value;
     }
     if ($key !== null && count($results) > 0) {
         $keys = $results->fetch($key)->all();
         return array_combine($keys, $values);
     }
     return $values;
 }
开发者ID:mechiko,项目名称:staff-october,代码行数:25,代码来源:NestedTree.php


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