PHP code example of schnittstabil / config_merge

1. Go to this page and download the library: Download schnittstabil/config_merge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

schnittstabil / config_merge example snippets


use function Schnittstabil\ConfigMerge\config_merge;

$target = json_decode(<<<'EOD'
{
    "files": ["src", "tests"],
    "opts": {
        "unicorns": 0,
        "leprechauns": 666
    }
}
EOD
);

$source = json_decode(<<<'EOD'
{
    "files": ["target"],
    "opts": {
        "unicorns": 42
    }
}
EOD
);

json_encode(config_merge($target, $source), JSON_PRETTY_PRINT);
/* =>
{
    "files": [
        "target"
    ],
    "opts": {
        "unicorns": 42,
        "leprechauns": 666
    }
}
*/

/**
 * Merge two configs.
 *
 * @param mixed $target       Target config
 * @param mixed $source       Source config
 * @param bool  $appendArrays if true use `array_merge`
 *
 * @return mixed The merged config
 */
function config_merge($target, $source, $appendArrays = false)