You can use this function to achieve desired result. It uses php eval()
function, despite on there historically a lot of doubts related to it
function ini($file) {
// Parse ini file
$ini = parse_ini_file($file, true);
// Foreach section
foreach ($ini as $sectionName => $sectionParamA) {
// Foreach param within section
foreach ($sectionParamA as $sectionParamK => $sectionParamV) {
// If param name contains '.'
if (preg_match('/\./', $sectionParamK)) {
// Get the levels
$levelA = explode('.', $sectionParamK);
// Declare/reset the $depth array
$depth = array();
// Foreach level except last level
for ($i = 0; $i < count($levelA) - 1; $i++) {
// Build the list of parent array dimensions
for ($d = 0; $d < count($depth); $d++)
$depth[$d] = str_replace('$i', '$i-' . ($i - $d), $depth[$d]);
// Append current array dimension
$depth[] = '[$levelA[$i]]';
// Check if current-level value is already an array
// (so it mean this it contains key-value pairs) and if so -
if (eval('return is_array($sectionParamA' . implode('', $depth) . ');')) {
// If the value of the param at certain-depth-level dimension is not yet an instance
// of ArrayObject class
if (!eval('return is_array($sectionParamA' . implode('', $depth) . '[' . $levelA[$i+1]. ']);'))
// Setup it
eval('$sectionParamA' . implode('', $depth) . '[' . $levelA[$i+1]. '] = $sectionParamA[$sectionParamK];');
// Else
} else {
// Setup the param value as a value of certain-depth-level dimension key within array
eval('$sectionParamA' . implode('', $depth) . ' = array(
$levelA[$i+1] => $sectionParamA[$sectionParamK]
);');
}
}
// Unset orinal param name and it's value, as now param name was parsed and converted
// to nesting arrays
unset($sectionParamA[$sectionParamK]);
}
}
// Update section
$ini[$sectionName] = $sectionParamA;
}
// Return
return $ini;
}