This is my class for parsing ini files in a multidimensional array:
class Cubique_Config { const SEPARATOR = '.'; private static $_data = null; public static function get() { if (is_null(self::$_data)) { $commonIniFile = APP . '/config' . '/common.ini'; $envIniFile = APP . '/config' . '/' . ENV . '.ini'; if (!file_exists($commonIniFile)) { throw new Exception('\'' . $commonIniFile . '\' config file not found'); } if (!file_exists($envIniFile)) { throw new Exception('\'' . $envIniFile . '\' config file not found'); } $commonIni = parse_ini_file($commonIniFile); $envIni = parse_ini_file($envIniFile); $mergedIni = array_merge($commonIni, $envIni); self::$_data = array(); foreach ($mergedIni as $rowKey => $rowValue) { $explodedRow = explode(self::SEPARATOR, $rowKey); self::$_data = array_merge_recursive(self::$_data, self::_subArray($explodedRow, $rowValue)); } } return self::$_data; } private static function _subArray($explodedRow, $value) { $result = null; $explodedRow = array_values($explodedRow); if (count($explodedRow)) { $firstItem = $explodedRow[0]; unset($explodedRow[0]); $result[$firstItem] = self::_subArray($explodedRow, $value); } else { $result = $value; } return $result; } }
pltvs source share