merge() public static method

If each array has an element with the same string key value, the latter will overwrite the former (different from array_merge_recursive). Recursive merging will be conducted if both arrays have an element of array type and are having the same key. For integer-keyed elements, the elements from the latter array will be appended to the former array. You can use [[UnsetArrayValue]] object to unset value from previous array or [[ReplaceArrayValue]] to force replace former value instead of recursive merging.
public static merge ( array $a, array $b ) : array
$a array array to be merged to
$b array array to be merged from. You can specify additional arrays via third argument, fourth argument etc.
return array the merged array (the original arrays are not changed.)
 public function actionIndex($search)
 {
     if ($search != null && $search != '') {
         $search = htmlspecialchars($search, ENT_HTML5);
         $activitySearchModel = new ActivitySearchGlobal();
         $activitySearchModel->globalSearch = $search;
         $activitySearchModelDataProvider = $activitySearchModel->search(Yii::$app->request->queryParams);
         $outdoorAttractionSearchModel = new OutsideAttractionSearchGlobal();
         $outdoorAttractionSearchModel->globalSearch = $search;
         $outdoorAttractionDataProvider = $outdoorAttractionSearchModel->search(Yii::$app->request->queryParams);
         $dataProvider = BaseArrayHelper::merge($activitySearchModelDataProvider, $outdoorAttractionDataProvider);
         if (Yii::$app->user->can('postIndex')) {
             $postSearchModel = new PostSearchGlobal();
             $postSearchModel->globalSearch = $search;
             $postDataProvider = $postSearchModel->search(Yii::$app->request->queryParams);
             $dataProvider = BaseArrayHelper::merge($dataProvider, $postDataProvider);
             $postReplySearchModel = new PostReplaySearchGlobal();
             $postReplySearchModel->globalSearch = $search;
             $postReplyDataProvider = $postReplySearchModel->search(Yii::$app->request->queryParams);
             $dataProvider = BaseArrayHelper::merge($dataProvider, $postReplyDataProvider);
         }
         if (Yii::$app->user->can('announcementIndex')) {
             $announcementSearchModel = new AnnouncementSearchGlobal();
             $announcementSearchModel->globalSearch = $search;
             $announcementDataProvider = $announcementSearchModel->search(Yii::$app->request->queryParams);
             $dataProvider = BaseArrayHelper::merge($dataProvider, $announcementDataProvider);
         }
         return $this->render('index', ['input' => $search, 'result' => $dataProvider]);
     } else {
         throw new ForbiddenHttpException(Yii::t('yii', 'Input something'));
     }
 }
 public function beforeAction($event)
 {
     $this->requestAction = $event->action;
     $this->requestHeaders = \Yii::$app->request->getHeaders();
     $this->requestData = BaseArrayHelper::merge(\Yii::$app->request->getBodyParams(), \Yii::$app->request->get());
     $this->requestMethod = \Yii::$app->request->getMethod();
     if ($this->requestMethod === 'OPTIONS') {
         return;
     }
     $this->checkAction();
     $this->checkMethod();
     $this->checkRequestStructure();
     $this->checkHeaders();
     return true;
 }
示例#3
0
 private function getImagesFinder($additionWhere = false)
 {
     $base = ['itemId' => $this->owner->id, 'modelName' => $this->getModule()->getShortClass($this->owner)];
     if ($additionWhere) {
         $base = \yii\helpers\BaseArrayHelper::merge($base, $additionWhere);
     }
     return $base;
 }
示例#4
0
文件: index.php 项目: fg/yii2-modular
<?php

/**
 * Hello world!
 */
if (isset($_SERVER['YII_ENV']) && $_SERVER['YII_ENV'] === 'DEV') {
    defined('YII_DEBUG') or define('YII_DEBUG', true);
    defined('YII_ENV') or define('YII_ENV', 'dev');
}
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/../config/bootstrap.php';
// Merge global and local configs
$config = (require __DIR__ . '/../config/web.php');
$localConfigPath = __DIR__ . '/../config/local/web.php';
if (file_exists($localConfigPath)) {
    $localConfig = (require $localConfigPath);
    $config = \yii\helpers\BaseArrayHelper::merge($config, $localConfig);
}
// Classes configuration (via Dependency Injection)
// http://www.yiiframework.com/doc-2.0/guide-concept-di-container.html
require __DIR__ . '/../config/di.php';
(new yii\web\Application($config))->run();
示例#5
0
 /**
  * @param string|null $to
  * @param string|null $subject
  * @param string|null $view
  * @param string|null $sender
  * @param array $params{'user', 'reply_to', 'body', 'header', 'mandrill_template_name', 'tags', 'vars', 'from_name'}
  */
 function __construct($to = null, $subject = null, $view = null, $sender = null, $params = [])
 {
     $this->to = $to;
     $this->subject = $subject;
     $this->view = $view;
     $this->params = $params;
     $c1 = $c2 = $c3 = $c4 = $cfg = [];
     if (file_exists(\Yii::getAlias('@app') . '/../common/config/' . '/main-local.php')) {
         $c1 = (require \Yii::getAlias('@app') . '/../common/config/' . '/main-local.php');
     }
     if (file_exists(\Yii::getAlias('@app') . '/../common/config/' . '/main.php')) {
         $c2 = (require \Yii::getAlias('@app') . '/../common/config/' . '/main.php');
     }
     if (file_exists(\Yii::getAlias('@app') . '/../frontend/config/' . '/main.php')) {
         $c3 = (require \Yii::getAlias('@app') . '/../frontend/config/' . '/main.php');
     }
     if (file_exists(\Yii::getAlias('@app') . '/../frontend/config/' . '/main-local.php')) {
         $c4 = (require \Yii::getAlias('@app') . '/../frontend/config/' . '/main-local.php');
     }
     $cfg = \Yii\helpers\BaseArrayHelper::merge($c1, $c2);
     $cfg = \Yii\helpers\BaseArrayHelper::merge($cfg, $c3);
     $cfg = \Yii\helpers\BaseArrayHelper::merge($cfg, $c4);
     if (isset($cfg['components']['mailer'])) {
         $mailer_config = $cfg['components']['mailer'];
     }
     if (isset($cfg['components']['mailer']['apikey'])) {
         $this->apikey = $cfg['components']['mailer']['apikey'];
     }
     if (isset($mailer_config['viewPath'])) {
         $this->viewPath = $mailer_config['viewPath'];
     }
     if ($this->sender === null) {
         $this->sender = isset(\Yii::$app->params['adminEmail']) ? \Yii::$app->params['adminEmail'] : '*****@*****.**';
     }
     if ($this->replyTo === null) {
         $this->replyTo = isset($this->params['reply_to']) ? $this->params['reply_to'] : '*****@*****.**';
     }
     if ($this->body === null) {
         $this->body = isset($this->params['body']) ? $this->params['body'] : null;
     }
     if ($this->header === null) {
         $this->header = isset($this->params['header']) ? $this->params['header'] : null;
     }
     if ($this->mandrill_template_name === null) {
         $this->mandrill_template_name = isset($this->params['mandrill_template_name']) ? $this->params['mandrill_template_name'] : null;
     }
     if ($this->tags === null) {
         $this->tags = isset($this->params['tags']) ? $this->params['tags'] : ['razzd'];
     }
     if ($this->vars === null) {
         $this->vars = isset($this->params['vars']) ? $this->params['vars'] : null;
     }
     if ($this->fromName === null) {
         $this->fromName = isset($this->params['from_name']) ? $this->params['from_name'] : 'Your friendly manager';
     }
 }
示例#6
0
 public function init()
 {
     $this->assignRule();
     $this->rules = BaseArrayHelper::merge($this->mainRules, $this->rules);
     return parent::init();
 }