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


PHP Arr::pluck方法代码示例

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


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

示例1: explode

 /**
  * Get an item from an array or object using "dot" notation.
  *
  * @param  mixed   $target
  * @param  string|array  $key
  * @param  mixed   $default
  * @return mixed
  */
 function data_get($target, $key, $default = null)
 {
     if (is_null($key)) {
         return $target;
     }
     $key = is_array($key) ? $key : explode('.', $key);
     while (($segment = array_shift($key)) !== null) {
         if ($segment === '*') {
             if ($target instanceof Collection) {
                 $target = $target->all();
             } elseif (!is_array($target)) {
                 return value($default);
             }
             $result = Arr::pluck($target, $key);
             return in_array('*', $key) ? Arr::collapse($result) : $result;
         }
         if (Arr::accessible($target) && Arr::exists($target, $segment)) {
             $target = $target[$segment];
         } elseif (is_object($target) && isset($target->{$segment})) {
             $target = $target->{$segment};
         } else {
             return value($default);
         }
     }
     return $target;
 }
开发者ID:sa7bi,项目名称:euro16,代码行数:34,代码来源:helpers.php

示例2: testBulkOperationException

 public function testBulkOperationException()
 {
     $bulkItems = new Collection([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]]);
     $items = [['create' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 1, 'status' => 409, 'error' => ['type' => 'document_already_exists_exception', 'reason' => '[my_index][1]: document already exists', 'shard' => '1', 'index' => 'my_index']]], ['update' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 2, 'status' => 404, 'error' => ['type' => 'document_missing_exception', 'reason' => '[my_index][2]: document missing', 'shard' => '-1', 'index' => 'my_index']]], ['delete' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 3, 'status' => 404, 'found' => false]], ['index' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 4, 'status' => 200]]];
     $e = BulkOperationException::createForResults($items, $bulkItems->all());
     $failedItems = $e->getFailedItems();
     $failedIds = Arr::pluck($failedItems, 'id');
     $this->assertEquals([1, 2], $failedIds);
 }
开发者ID:elodex,项目名称:elodex,代码行数:9,代码来源:BulkOperationTest.php

示例3: fire

 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $ids = $this->argument('id');
     if (count($ids) === 1 && $ids[0] === 'all') {
         $ids = Arr::pluck($this->laravel['queue.failer']->all(), 'id');
     }
     foreach ($ids as $id) {
         $this->retryJob($id);
     }
 }
开发者ID:iarmoa,项目名称:gaia,代码行数:15,代码来源:RetryCommand.php

示例4: pluck

 /**
  * Get the values of a given key.
  *
  * @param  string  $value
  * @param  string|null  $key
  * @return static
  */
 public function pluck($value, $key = null)
 {
     return new static(Arr::pluck($this->items, $value, $key));
 }
开发者ID:jeandrocouto,项目名称:warmupdelivery,代码行数:11,代码来源:Collection.php

示例5: pluck

 /**
  * Get an array with the values of a given column.
  *
  * @param  string  $column
  * @param  string|null  $key
  * @return array
  */
 public function pluck($column, $key = null)
 {
     $results = $this->get(is_null($key) ? [$column] : [$column, $key]);
     // If the columns are qualified with a table or have an alias, we cannot use
     // those directly in the "pluck" operations since the results from the DB
     // are only keyed by the column itself. We'll strip the table out here.
     return Arr::pluck($results, $this->stripTableForPluck($column), $this->stripTableForPluck($key));
 }
开发者ID:denise92,项目名称:cms,代码行数:15,代码来源:Builder.php

示例6:

 /**
  * Pluck an array of values from an array.
  *
  * @param  array   $array
  * @param  string  $value
  * @param  string  $key
  * @return array
  */
 function array_pluck($array, $value, $key = null)
 {
     return Arr::pluck($array, $value, $key);
 }
开发者ID:eunicon,项目名称:meetup,代码行数:12,代码来源:helpers.php

示例7: function

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Response;
use Zend\Feed\Exception\InvalidArgumentException;
use Zend\Feed\Writer\Entry;
use Zend\Feed\Writer\Feed;
Route::get('/feeds/{path}', function ($path) {
    /** @type FeedModel $model */
    $model = FeedModel::where('path', '=', $path)->first();
    if ($model === null) {
        return Response::make('Not Found', 404);
    }
    $feed = new Feed();
    $feed->setTitle($model->getAttribute('title'))->setDescription($model->getAttribute('description'))->setBaseUrl(Url::to('/'))->setGenerator('OctoberCMS/Adrenth.RssFetcher')->setId('Adrenth.RssFecther.' . $model->getAttribute('id'))->setLink(Url::to('/feeds/' . $path))->setFeedLink(Url::to('/feeds/' . $path), $model->getAttribute('type'))->setDateModified()->addAuthor(['name' => 'OctoberCMS']);
    /** @type Collection $sources */
    $sources = $model->sources;
    $ids = Arr::pluck($sources->toArray(), 'id');
    $items = [];
    Source::with(['items' => function ($builder) use(&$items, $model) {
        $items = $builder->where('is_published', '=', 1)->whereDate('pub_date', '=', date('Y-m-d'))->orderBy('pub_date', 'desc')->limit($model->getAttribute('max_items'))->get();
    }])->whereIn('id', $ids)->where('is_enabled', '=', 1)->get();
    /** @type Item $item */
    foreach ($items as $item) {
        try {
            $entry = new Entry();
            $entry->setId((string) $item->getAttribute('id'))->setTitle($item->getAttribute('title'))->setDescription($item->getAttribute('description'))->setLink($item->getAttribute('link'))->setDateModified($item->getAttribute('pub_date'));
            $comments = $item->getAttribute('comments');
            if (!empty($comments)) {
                $entry->setCommentLink($comments);
            }
            $category = $item->getAttribute('category');
            if (!empty($category)) {
开发者ID:adrenth,项目名称:rssfetcher,代码行数:31,代码来源:routes.php

示例8: alreadyJoined

 /**
  * Determine whether given table has been already joined.
  *
  * @param  \Sofa\Eloquence\Builder $query
  * @param  string  $table
  * @return boolean
  */
 protected function alreadyJoined(Builder $query, $table)
 {
     $joined = Arr::pluck((array) $query->getQuery()->joins, 'table');
     return in_array($table, $joined);
 }
开发者ID:rickatultraware,项目名称:eloquence,代码行数:12,代码来源:Mappable.php

示例9: prepareChartData

 /**
  * Prepare chart data.
  *
  * @param  \Arcanedev\LogViewer\Tables\StatsTable  $stats
  *
  * @return string
  */
 protected function prepareChartData(StatsTable $stats)
 {
     $totals = $stats->totals()->all();
     return json_encode(['labels' => Arr::pluck($totals, 'label'), 'datasets' => [['data' => Arr::pluck($totals, 'value'), 'backgroundColor' => Arr::pluck($totals, 'color'), 'hoverBackgroundColor' => Arr::pluck($totals, 'highlight')]]]);
 }
开发者ID:ARCANEDEV,项目名称:LogViewer,代码行数:12,代码来源:LogViewerController.php

示例10: pluck

 /**
  * Get an array with the values of a given column.
  *
  * @param  string  $column
  * @param  string|null  $key
  * @return array
  */
 public function pluck($column, $key = null)
 {
     $results = $this->get(is_null($key) ? [$column] : [$column, $key]);
     // Convert ObjectID's to strings
     if ($key == '_id') {
         $results = $results->map(function ($item) {
             $item['_id'] = (string) $item['_id'];
             return $item;
         });
     }
     $p = Arr::pluck($results, $column, $key);
     return $this->useCollections ? new Collection($p) : $p;
 }
开发者ID:philipbrown,项目名称:laravel-mongodb,代码行数:20,代码来源:Builder.php


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