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