« Return to Thread: Merging Zend_Config objects?

Re: Merging Zend_Config objects?

by Nico Edtinger-2 :: Rate this Message:

Reply to Author | View in Thread

<?php
function _fix_merge($array) {
        foreach($array as $k => $v) {
                if (!is_array($v)) {
                        continue;
                }
                if (is_int(key($v))) {
                        $array[$k] = $v[1];
                } else {
                        $array[$k] = _fix_merge($v);
                }
        }
       
        return $array;
}

$config1 = new Zend_Config_Ini(...);
$config2 = new Zend_Config_Ini(...);
$config = new Zend_Config(_fix_merge(array_merge_recursive($config1-
 >toArray(), $config2->toArray())));
?>

nico

Jack Sleight wrote:

> Hi,
> Has anyone implemented a method to allow merging of two Zend_Config  
> objects? Where the values in one will override the values in the  
> other? I need to do this because I have a generic module in one  
> folder (with a default config), that multiple sites use, and each  
> site needs to specify its own configuration for the module (with  
> the possibility of overriding the defaults).
> Thanks,
> --
> Jack

 « Return to Thread: Merging Zend_Config objects?