Example #1
0
 public function testFlatten()
 {
     $config = array('one' => 'hello world', 'two' => array('twoA' => array('one', 'two', 'three'), 'other' => 'value'));
     $expected = array('one' => 'hello world', 'two.twoA.0' => 'one', 'two.twoA.1' => 'two', 'two.twoA.2' => 'three', 'two.other' => 'value');
     $this->assertEquals($expected, config_flatten($config));
 }
Example #2
0
/**
 * Flatten a multi-dimensional associative array with dots.
 *
 * @param array $config
 * @param string $prepend
 * @return array
 */
function config_flatten(array $config, $prepend = '')
{
    $results = array();
    foreach ($config as $key => $value) {
        if (is_array($value)) {
            $results = array_merge($results, config_flatten($value, $prepend . $key . '.'));
        } else {
            $results[$prepend . $key] = $value;
        }
    }
    return $results;
}