N98\Util\ArrayFunctions::mergeArrays PHP Метод

mergeArrays() публичный статический Метод

If an integer key exists in both arrays, the value from the second array will be appended the the first array. If both values are arrays, they are merged together, else the value of the second array overwrites the one of the first array.
См. также: http://packages.zendframework.com/docs/latest/manual/en/index.html#zend-stdlib
public static mergeArrays ( array $a, array $b ) : array
$a array
$b array
Результат array
    public static function mergeArrays(array $a, array $b)
    {
        foreach ($b as $key => $value) {
            if (array_key_exists($key, $a)) {
                if (is_int($key)) {
                    $a[] = $value;
                } elseif (is_array($value) && is_array($a[$key])) {
                    $a[$key] = self::mergeArrays($a[$key], $value);
                } else {
                    $a[$key] = $value;
                }
            } else {
                $a[$key] = $value;
            }
        }
        return $a;
    }

Usage Example

 public function testExecute()
 {
     /**
      * Check autoloading
      */
     /* @var $application Application */
     $application = (require __DIR__ . '/../../../src/bootstrap.php');
     $application->setMagentoRootFolder($this->getTestMagentoRoot());
     $this->assertInstanceOf('\\N98\\Magento\\Application', $application);
     $loader = $application->getAutoloader();
     $this->assertInstanceOf('\\Composer\\Autoload\\ClassLoader', $loader);
     /**
      * Check version
      */
     $this->assertEquals(Application::APP_VERSION, trim(file_get_contents(__DIR__ . '/../../../version.txt')));
     /* @var $loader \Composer\Autoload\ClassLoader */
     $prefixes = $loader->getPrefixes();
     $this->assertArrayHasKey('N98', $prefixes);
     $distConfigArray = Yaml::parse(file_get_contents(__DIR__ . '/../../../config.yaml'));
     $configArray = array('autoloaders' => array('N98MagerunTest' => __DIR__ . '/_ApplicationTestSrc'), 'commands' => array('customCommands' => array(0 => 'N98MagerunTest\\TestDummyCommand'), 'aliases' => array(array('ssl' => 'sys:store:list'))), 'init' => array('options' => array('config_model' => 'N98MagerunTest\\AlternativeConfigModel')));
     $application->setAutoExit(false);
     $application->init(ArrayFunctions::mergeArrays($distConfigArray, $configArray));
     $application->run(new StringInput('list'), new NullOutput());
     // Check if autoloaders, commands and aliases are registered
     $prefixes = $loader->getPrefixes();
     $this->assertArrayHasKey('N98MagerunTest', $prefixes);
     $testDummyCommand = $application->find('n98mageruntest:test:dummy');
     $this->assertInstanceOf('\\N98MagerunTest\\TestDummyCommand', $testDummyCommand);
     $commandTester = new CommandTester($testDummyCommand);
     $commandTester->execute(array('command' => $testDummyCommand->getName()));
     $this->assertContains('dummy', $commandTester->getDisplay());
     $this->assertTrue($application->getDefinition()->hasOption('root-dir'));
     // check alias
     $this->assertInstanceOf('\\N98\\Magento\\Command\\System\\Store\\ListCommand', $application->find('ssl'));
 }
All Usage Examples Of N98\Util\ArrayFunctions::mergeArrays