Created
January 19, 2013 18:21
-
-
Save xat/4574119 to your computer and use it in GitHub Desktop.
The goal is to find a nice way to merge multiple configs where the inner-configs ($localConfig) are able to unset keys of the outer-configs ($globalConfig)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Global Configuration | |
$globalConfig = array | |
( | |
'key1' => 'val1', | |
'key2' => array | |
( | |
'key2.1' => 'val2.1', | |
'key2.2' => 'val2.2', | |
'key2.3' => 'val2.3' | |
) | |
'key3' => 'val3', | |
'key4' => array('val4.1', 'val4.2', 'val4.3', 'val4.4', 'val4.5') | |
); | |
// Local Configuration | |
$localConfig = array | |
( | |
'key1' => 'val1_local', | |
'key2' => array | |
( | |
'key2.1' => NULL, // NULL is used to unset this key | |
'key2.4' => 'val2.4_local' | |
), | |
'key4' => array('val4.1_local') | |
); | |
// After merging $globalConfig and $localConfig the goal is | |
// that we get this as a result: | |
$targetConfig = array | |
( | |
'key1' => 'val1_local', | |
'key2' => array | |
( | |
'key2.2' => 'val2.2', | |
'key2.3' => 'val2.3', | |
'key2.4' => 'val2.4_local' | |
), | |
'key3' => 'val3', | |
'key4' => array('val4.1_local') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment