src/IniWriter.php
public function writeToString(array $config, $header = '')
    {
        $ini = $header;

        $sectionNames = array_keys($config);

        foreach ($sectionNames as $sectionName) {
            $section = $config[$sectionName];

            // no point in writing empty sections
            if (empty($section)) {
                continue;
            }

            if (! is_array($section)) {
                throw new IniWritingException(sprintf("Section \"%s\" doesn't contain an array of values", $sectionName));
            }

            $ini .= "[$sectionName]\n";

            foreach ($section as $option => $value) {
                if (is_numeric($option)) {
                    $option = $sectionName;
                    $value = array($value);
                }

                if (is_array($value)) {
                    foreach ($value as $currentValue) {
                        $ini .= $option . '[] = ' . $this->encodeValue($currentValue) . "\n";
                    }
                } else {
                    $ini .= $option . ' = ' . $this->encodeValue($value) . "\n";
                }
            }

            $ini .= "\n";
        }

        return $ini;
    }
public function writeToString(array $config, $header = '')
    {
        $ini = $header;

        $sectionNames = array_keys($config);

        foreach ($sectionNames as $sectionName) {
            $section = $config[$sectionName];

            // no point in writing empty sections
            if (empty($section)) {
                continue;
            }

            if (! is_array($section)) {
                throw new IniWritingException(sprintf("Section \"%s\" doesn't contain an array of values", $sectionName));
            }

            $ini .= "[$sectionName]\n";

            foreach ($section as $option => $value) {
                if (is_numeric($option)) {
                    $option = $sectionName;
                    $value = array($value);
                }

                if (is_array($value)) {
                    foreach ($value as $currentValue) {
                        $ini .= $option . '[] = ' . $this->encodeValue($currentValue) . "\n";
                    }
                } else {
                    $ini .= $option . ' = ' . $this->encodeValue($value) . "\n";
                }
            }

            $ini .= "\n";
        }

        return $ini;
    }
public function writeToString ( array $ config , $ header = '' ) { $ ini = $ header ; $ sectionNames = array_keys ( $ config ) ; foreach ( $ sectionNames as $ sectionName ) { $ section = $ config [ $ sectionName ] ; // no point in writing empty sections if ( empty ( $ section ) ) { continue ; } if ( ! is_array ( $ section ) ) { throw new IniWritingException ( sprintf ( "Section \"%s\" doesn't contain an array of values" , $ sectionName ) ) ; } $ ini .= "[$sectionName]\n" ; foreach ( $ section as $ option => $ value ) { if ( is_numeric ( $ option ) ) { $ option = $ sectionName ; $ value = array ( $ value ) ; } if ( is_array ( $ value ) ) { foreach ( $ value as $ currentValue ) { $ ini .= $ option . '[] = ' . $ this -> encodeValue ( $ currentValue ) . "\n" ; } } else { $ ini .= $ option . ' = ' . $ this -> encodeValue ( $ value ) . "\n" ; } } $ ini .= "\n" ; } return $ ini ; }
Writes an array configuration to a INI string and returns it.

The array provided must be multidimensional, indexed by section names:

```
array(
'Section 1' => array(
'value1' => 'hello',
'value2' => 'world',
),
'Section 2' => array(
'value3' => 'foo',
)
);
```

@param array $config
@param string $header Optional header to insert at the top of the file.
@return string
@throws IniWritingException
Writes an array configuration to a INI string and returns it .