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


PHP array_build函数代码示例

本文整理汇总了PHP中array_build函数的典型用法代码示例。如果您正苦于以下问题:PHP array_build函数的具体用法?PHP array_build怎么用?PHP array_build使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: to_array

 /**
  * Converts an array, object, or string to an array.
  * 
  * @param mixed $thing Array, object, or string (JSON, serialized, or XML).
  * @return array
  */
 function to_array($thing)
 {
     if (is_array($thing)) {
         return array_build($thing);
     }
     if (is_object($thing)) {
         return array_build(object_to_array($thing));
     }
     if (is_string($thing)) {
         if (is_json($thing)) {
             return json_decode($thing, true);
         }
         if (is_serialized($thing)) {
             return to_array(unserialize($thing));
         }
         if (is_xml($thing)) {
             return xml_decode($thing, true);
         }
     }
     return (array) $thing;
 }
开发者ID:wells5609,项目名称:php-util,代码行数:27,代码来源:array.php

示例2: setPreferences

 /**
  * Sets mail blocking preferences for a user. Eg:
  *
  * MailBlocker::setPreferences($user, [acme.blog::post.new_reply => 0])
  *
  * MailBlocker::setPreferences($user, [acme.blog::post.new_reply => 0], [fillable => [acme.blog::post.new_reply]])
  *
  * MailBlocker::setPreferences($user, [template_alias => 0], [aliases => [template_alias => acme.blog::post.new_reply]])
  *
  * Supported options:
  * - aliases: Alias definitions, with alias as key and template as value.
  * - fillable: An array of expected templates, undefined templates are ignored.
  * - verify: Only allow mail templates that are registered in the system.
  *
  * @param  array $templates Template name as key and boolean as value. If false, template is blocked. 
  * @param  RainLab\User\Models\User $user
  * @param  array $options
  * @return void
  */
 public static function setPreferences($user, $templates, $options = [])
 {
     $templates = (array) $templates;
     if (!$user) {
         throw new Exception('A user must be provided for MailBlocker::setPreferences');
     }
     extract(array_merge(['aliases' => [], 'fillable' => [], 'verify' => false], $options));
     if ($aliases) {
         $fillable = array_merge($fillable, array_values($aliases));
         $templates = array_build($templates, function ($key, $value) use($aliases) {
             return [array_get($aliases, $key, $key), $value];
         });
     }
     if ($fillable) {
         $templates = array_intersect_key($templates, array_flip($fillable));
     }
     if ($verify) {
         $existing = MailTemplate::listAllTemplates();
         $templates = array_intersect_key($templates, $existing);
     }
     $currentBlocks = array_flip(static::checkAllForUser($user));
     foreach ($templates as $template => $value) {
         // User wants to receive mail and is blocking
         if ($value && isset($currentBlocks[$template])) {
             static::removeBlock($template, $user);
         } elseif (!$value && !isset($currentBlocks[$template])) {
             static::addBlock($template, $user);
         }
     }
 }
开发者ID:BOOMER74,项目名称:user-plugin,代码行数:49,代码来源:MailBlocker.php

示例3: __construct

 /**
  * @inheritdoc
  */
 public function __construct($items = null, $class_slug = null, $key_by = null)
 {
     $items = is_null($items) ? [] : $items;
     if ($items instanceof \Illuminate\Support\Collection) {
         return parent::__construct($items);
     }
     if ($class_slug) {
         $items = array_map(function ($item) use($class_slug) {
             if (is_null($item)) {
                 return $item;
             }
             if (!is_array($item)) {
                 throw new \Exception("Failed to cast a model");
             }
             $class = Model::getModelClass($class_slug);
             return new $class($item);
         }, $items);
     }
     if ($key_by) {
         $items = array_build($items, function ($key, $value) use($key_by) {
             /** @var Model $value */
             $key = $value instanceof Model ? $value->get($key_by) : data_get($value, $key_by);
             return [$key, $value];
         });
     }
     return parent::__construct($items);
 }
开发者ID:sourcestream,项目名称:highcore-api,代码行数:30,代码来源:Collection.php

示例4: getConfiguredStyles

 /**
  * Same as getConfigured but uses special style structure.
  * @return mixed
  */
 public static function getConfiguredStyles($key, $default = null)
 {
     $instance = static::instance();
     $value = $instance->get($key);
     $defaultValue = $instance->getDefaultValue($key);
     if (is_array($value)) {
         $value = array_build($value, function ($key, $value) {
             return [array_get($value, 'class_name'), array_get($value, 'class_label')];
         });
     }
     return $value != $defaultValue ? $value : $default;
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:16,代码来源:EditorSetting.php

示例5: getImagesAttribute

 public function getImagesAttribute()
 {
     if (!$this->image->originalFilename()) {
         return [];
     }
     return array_build($this->image->getConfig()->styles, function ($index, $style) {
         if (!($size = $style->dimensions)) {
             list($w, $h) = getimagesize($this->image->path());
             $size = "{$w}x{$h}";
         }
         return [$style->name, ['url' => $this->image->url($style->name), 'name' => $this->attributes['image_file_name'], 'dimensions' => $size, 'type' => $this->attributes['image_content_type']]];
     });
 }
开发者ID:adminarchitect,项目名称:news,代码行数:13,代码来源:NewsItem.php

示例6: get

 /**
  * @return \Bolt\Core\Storage\ContentCollection
  */
 public function get($wheres = array(), $loadRelated = true, $sort = null, $order = 'asc', $offset = null, $limit = null, $search = null)
 {
     $selects = $this->getSelects();
     $recordsQuery = $this->model;
     if ($loadRelated) {
         $recordsQuery = $recordsQuery->with(array('incoming', 'outgoing'));
     }
     foreach ($this->getRelationTableJoin($wheres) as $join) {
         $recordsQuery = $recordsQuery->join($join['table'], $join['left'], '=', $join['right']);
     }
     $recordsQuery = $recordsQuery->select($selects);
     foreach ($wheres as $key => $value) {
         if (is_array($value) && count($value) > 0) {
             $recordsQuery = $recordsQuery->whereIn($key, $value);
         } else {
             $recordsQuery = $recordsQuery->where($key, '=', $value);
         }
     }
     if (!is_null($search)) {
         $searchFields = $this->contentType->getSearchFields()->getDatabaseFields();
         $recordsQuery->where(function ($query) use($searchFields, $search) {
             foreach ($searchFields as $searchField) {
                 $query->orWhere(new Expression('LOWER(' . $searchField->getKey() . ')'), 'LIKE', '%' . strtolower($search) . '%');
             }
         });
     }
     $total = $recordsQuery->count();
     if (!is_null($offset)) {
         $recordsQuery = $recordsQuery->skip($offset);
     }
     if (!is_null($limit)) {
         $recordsQuery = $recordsQuery->take($limit);
     }
     if (!is_null($sort)) {
         $recordsQuery = $recordsQuery->orderBy($sort, $order);
     }
     $records = $recordsQuery->get()->toArray();
     $me = $this;
     $records = array_build($records, function ($key, $record) use($me) {
         $record = $me->callGetters($record);
         return array($record['id'], $record);
     });
     if ($loadRelated) {
         $records = $this->loadRelatedFor($records);
     }
     return $this->app['contents.factory']->create($records, $this->contentType, $total);
 }
开发者ID:vespakoen,项目名称:bolt-core,代码行数:50,代码来源:EloquentRepository.php

示例7: parseResult

 /**
  * @param string $result
  * @return array
  */
 protected function parseResult($result)
 {
     $rows = json_decode($result, true);
     $all = [];
     foreach ($rows as $row) {
         // Flatten the array to dot notation keys then replace dots with underscores
         $row = array_build(array_dot($row), function ($key, $value) {
             return [str_replace('.', '_', $key), $value];
         });
         if (!empty($row['month'])) {
             $row['month'] = Carbon::createFromFormat('Y-m', $row['month'])->startOfMonth()->toIso8601String();
         }
         if (!empty($row['outcome_status_date'])) {
             $row['outcome_status_date'] = Carbon::createFromFormat('Y-m', $row['outcome_status_date'])->startOfMonth()->toIso8601String();
         }
         if (!empty($row['location_latitude']) && !empty($row['location_longitude'])) {
             $row['location'] = sprintf('(%s, %s)', $row['location_latitude'], $row['location_longitude']);
         }
         $all[$row['id']] = $row;
     }
     return $all;
 }
开发者ID:BathHacked,项目名称:street-level-crime,代码行数:26,代码来源:Fetcher.php

示例8: parseFilters

 /**
  * Parse the given filter string.
  *
  * @param  string  $filters
  * @return array
  */
 public static function parseFilters($filters)
 {
     return array_build(static::explodeFilters($filters), function ($key, $value) {
         return Route::parseFilter($value);
     });
 }
开发者ID:hilmysyarif,项目名称:l4-bootstrap-admin,代码行数:12,代码来源:Route.php

示例9: getPreferencesAttribute

 /**
  * Get the values of all registered preferences for this user, by
  * transforming their stored preferences and merging them with the defaults.
  *
  * @param string $value
  * @return array
  */
 public function getPreferencesAttribute($value)
 {
     $defaults = array_build(static::$preferences, function ($key, $value) {
         return [$key, $value['default']];
     });
     $user = array_only((array) json_decode($value, true), array_keys(static::$preferences));
     return array_merge($defaults, $user);
 }
开发者ID:ygbhf,项目名称:flarum-full,代码行数:15,代码来源:User.php

示例10: db_query_indexed

function db_query_indexed($index, $sql, $params = array())
{
    $res = db_query($sql, $params);
    return array_build($res, function ($i, $data) use($index) {
        return array($data[$index], $data);
    });
}
开发者ID:sanshilei,项目名称:password,代码行数:7,代码来源:db.php

示例11: applyScopeToQuery

 /**
  * Applies a filter scope constraints to a DB query.
  * @param  string $scope
  * @param  Builder $query
  * @return Builder
  */
 public function applyScopeToQuery($scope, $query)
 {
     if (is_string($scope)) {
         $scope = $this->getScope($scope);
     }
     if (!$scope->value) {
         return;
     }
     $value = is_array($scope->value) ? array_keys($scope->value) : $scope->value;
     /*
      * Condition
      */
     if ($scopeConditions = $scope->conditions) {
         if (is_array($value)) {
             $filtered = implode(',', array_build($value, function ($key, $_value) {
                 return [$key, Db::getPdo()->quote($_value)];
             }));
         } else {
             $filtered = Db::getPdo()->quote($value);
         }
         $query->whereRaw(strtr($scopeConditions, [':filtered' => $filtered]));
     }
     /*
      * Scope
      */
     if ($scopeMethod = $scope->scope) {
         $query->{$scopeMethod}($value);
     }
     return $query;
 }
开发者ID:janusnic,项目名称:23copperleaf,代码行数:36,代码来源:Filter.php

示例12: parseStringToArray

 /**
  * Parse string into an array of method names and argument lists.
  *
  * For example
  *   "where(id|name, =, *)"
  * becomes
  *   [
  *      "where" => ["id|name", "=", "*"]
  *   ]
  *
  * @param string $input
  * @return array
  */
 protected function parseStringToArray($input)
 {
     return array_build(preg_split('#(?<=\\))\\s*(?=[a-z])#i', $input), function ($index, $rule) {
         if (!preg_match('#^(?<method>[a-z]+)\\((?<args>[^)]*)\\)$#i', $rule, $clause)) {
             throw new InvalidArgumentException('Could not parse rule [' . $rule . ']');
         }
         return [$clause['method'], preg_split('#\\s*,\\s*#', $clause['args'])];
     });
 }
开发者ID:parsnick,项目名称:eloquentjs,代码行数:22,代码来源:Factory.php

示例13: trans

 /**
  * Looks up and translates a message by its string.
  * @param  string $messageId
  * @param  array  $params
  * @return string
  */
 public static function trans($messageId, $params)
 {
     $msg = static::get($messageId);
     $params = array_build($params, function ($key, $value) {
         return [':' . $key, $value];
     });
     $msg = strtr($msg, $params);
     return $msg;
 }
开发者ID:junksdesign,项目名称:stanfour4,代码行数:15,代码来源:Message.php

示例14: applyScopeToQuery

 /**
  * Applies a filter scope constraints to a DB query.
  * @param  string $scope
  * @param  Builder $query
  * @return Builder
  */
 public function applyScopeToQuery($scope, $query)
 {
     if (is_string($scope)) {
         $scope = $this->getScope($scope);
     }
     if (!$scope->value) {
         return;
     }
     switch ($scope->type) {
         case 'string':
             if ($scope->value && is_scalar($scope->value) && trim($scope->value)) {
                 if (array_get($scope->config, 'isNumericFindId') && is_numeric(trim($scope->value))) {
                     $query->where('id', trim($scope->value));
                 } else {
                     $query->searchWhere($scope->value, array_get($scope->config, 'fields') ?: [$scope->scopeName]);
                 }
             }
             break;
         case 'date':
         case 'range':
             $this->applyDateScopeToQuery($scope, $query);
             break;
         default:
             $value = is_array($scope->value) ? array_keys($scope->value) : $scope->value;
             /*
              * Condition
              */
             if ($scopeConditions = $scope->conditions) {
                 foreach ((array) $scopeConditions as $scopeKey => $scopeCondition) {
                     if (is_array($scopeConditions)) {
                         if (array_key_exists($scopeKey, $scope->value) == false) {
                             continue;
                         }
                     }
                     if (is_array($value)) {
                         $filtered = implode(',', array_build($value, function ($key, $_value) {
                             return [$key, Db::getPdo()->quote($_value)];
                         }));
                     } else {
                         $filtered = Db::getPdo()->quote($value);
                     }
                     $query->whereRaw(strtr($scopeCondition, [':filtered' => $filtered]));
                 }
             }
     }
     /*
      * Scope
      */
     if ($scopeMethod = $scope->scope) {
         $query->{$scopeMethod}($value);
     }
     return $query;
 }
开发者ID:grohman,项目名称:oc-idwidgets,代码行数:59,代码来源:Filter.php

示例15: errors

 protected function errors($validate, $errors)
 {
     if ($validate && $errors) {
         return implode(PHP_EOL, array_build($errors, function ($key, $val) {
             return [$key, $this->_render('error', $val)];
         }));
     }
     return '';
 }
开发者ID:master0mind,项目名称:Lavender,代码行数:9,代码来源:Renderer.php


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