protected function buildOutputString($sectionsarray)
{
$content = '';
$sections = '';
$globals = '';
if (!empty($sectionsarray)) {
// 2 loops to write `globals' on top, alternative: buffer
foreach ($sectionsarray as $section => $item) {
if (!is_array($item)) {
$value = $this->normalizeValue($item);
$globals .= $section . ' = ' . $value . $this->linebreak;
}
}
$content .= $globals;
foreach ($sectionsarray as $section => $item) {
if (is_array($item)) {
$sections .= $this->linebreak . "[" . $section . "]" . $this->linebreak;
foreach ($item as $key => $value) {
if (is_array($value)) {
foreach ($value as $arrkey => $arrvalue) {
$arrvalue = $this->normalizeValue($arrvalue);
$arrkey = $key . '[' . $arrkey . ']';
$sections .= $arrkey . ' = ' . $arrvalue . $this->linebreak;
}
} else {
$value = $this->normalizeValue($value);
$sections .= $key . ' = ' . $value . $this->linebreak;
}
}
}
}
$content .= $sections;
}
return $content;
}