lib/IniModifier.php
public function setValue($name, $value, $section = 0, $key = null)
    {
        $foundValue = false;
        $lastKey = -1; // last key in an array value
        if (isset($this->content[$section])) {
            // boolean to erase array values if the new value is not a new item for the array
            $deleteMode = false;
            foreach ($this->content[$section] as $k => $item) {
                if ($deleteMode) {
                    if ($item[0] == self::TK_ARR_VALUE && $item[1] == $name) {
                        $this->content[$section][$k] = array(self::TK_WS, '--');
                    }
                    continue;
                }

                // if the item is not a value or an array value, or not the same name
                if (($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE)
                    || $item[1] != $name) {
                    continue;
                }

                // if it is an array value, and if the key doesn't correspond
                if ($item[0] == self::TK_ARR_VALUE && $key !== null) {
                    if ($item[3] != $key || $key === '') {
                        $lastKey = $item[3];
                        continue;
                    }
                }
                if ($key !== null) {
                    // we add the value as an array value
                    if ($key === '') {
                        $key = 0;
                    }
                    $this->content[$section][$k] = array(self::TK_ARR_VALUE, $name,$value, $key);
                } else {
                    // we store the value
                    $this->content[$section][$k] = array(self::TK_VALUE, $name, $value);
                    if ($item[0] == self::TK_ARR_VALUE) {
                        // the previous value was an array value, so we erase other array values
                        $deleteMode = true;
                        $foundValue = true;
                        continue;
                    }
                }
                $foundValue = true;
                break;
            }
        } else {
            $this->content[$section] = array(array(self::TK_SECTION, '['.$section.']'));
        }
        if (!$foundValue) {
            if ($key === null) {
                $this->content[$section][] = array(self::TK_VALUE, $name, $value);
            } else {
                if ($lastKey != -1) {
                    ++$lastKey;
                } else {
                    $lastKey = 0;
                }
                $this->content[$section][] = array(self::TK_ARR_VALUE, $name, $value, $lastKey);
            }
        }

        $this->modified = true;
    }
public function setValue($name, $value, $section = 0, $key = null)
    {
        $foundValue = false;
        $lastKey = -1; // last key in an array value
        if (isset($this->content[$section])) {
            // boolean to erase array values if the new value is not a new item for the array
            $deleteMode = false;
            foreach ($this->content[$section] as $k => $item) {
                if ($deleteMode) {
                    if ($item[0] == self::TK_ARR_VALUE && $item[1] == $name) {
                        $this->content[$section][$k] = array(self::TK_WS, '--');
                    }
                    continue;
                }

                // if the item is not a value or an array value, or not the same name
                if (($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE)
                    || $item[1] != $name) {
                    continue;
                }

                // if it is an array value, and if the key doesn't correspond
                if ($item[0] == self::TK_ARR_VALUE && $key !== null) {
                    if ($item[3] != $key || $key === '') {
                        $lastKey = $item[3];
                        continue;
                    }
                }
                if ($key !== null) {
                    // we add the value as an array value
                    if ($key === '') {
                        $key = 0;
                    }
                    $this->content[$section][$k] = array(self::TK_ARR_VALUE, $name,$value, $key);
                } else {
                    // we store the value
                    $this->content[$section][$k] = array(self::TK_VALUE, $name, $value);
                    if ($item[0] == self::TK_ARR_VALUE) {
                        // the previous value was an array value, so we erase other array values
                        $deleteMode = true;
                        $foundValue = true;
                        continue;
                    }
                }
                $foundValue = true;
                break;
            }
        } else {
            $this->content[$section] = array(array(self::TK_SECTION, '['.$section.']'));
        }
        if (!$foundValue) {
            if ($key === null) {
                $this->content[$section][] = array(self::TK_VALUE, $name, $value);
            } else {
                if ($lastKey != -1) {
                    ++$lastKey;
                } else {
                    $lastKey = 0;
                }
                $this->content[$section][] = array(self::TK_ARR_VALUE, $name, $value, $lastKey);
            }
        }

        $this->modified = true;
    }
public function setValue ( $ name , $ value , $ section = 0 , $ key = null ) { $ foundValue = false ; $ lastKey = - 1 ; // last key in an array value if ( isset ( $ this -> content [ $ section ] ) ) { // boolean to erase array values if the new value is not a new item for the array $ deleteMode = false ; foreach ( $ this -> content [ $ section ] as $ k => $ item ) { if ( $ deleteMode ) { if ( $ item [ 0 ] == self :: TK_ARR_VALUE && $ item [ 1 ] == $ name ) { $ this -> content [ $ section ] [ $ k ] = array ( self :: TK_WS , '--' ) ; } continue ; } // if the item is not a value or an array value, or not the same name if ( ( $ item [ 0 ] != self :: TK_VALUE && $ item [ 0 ] != self :: TK_ARR_VALUE ) || $ item [ 1 ] != $ name ) { continue ; } // if it is an array value, and if the key doesn't correspond if ( $ item [ 0 ] == self :: TK_ARR_VALUE && $ key !== null ) { if ( $ item [ 3 ] != $ key || $ key === '' ) { $ lastKey = $ item [ 3 ] ; continue ; } } if ( $ key !== null ) { // we add the value as an array value if ( $ key === '' ) { $ key = 0 ; } $ this -> content [ $ section ] [ $ k ] = array ( self :: TK_ARR_VALUE , $ name , $ value , $ key ) ; } else { // we store the value $ this -> content [ $ section ] [ $ k ] = array ( self :: TK_VALUE , $ name , $ value ) ; if ( $ item [ 0 ] == self :: TK_ARR_VALUE ) { // the previous value was an array value, so we erase other array values $ deleteMode = true ; $ foundValue = true ; continue ; } } $ foundValue = true ; break ; } } else { $ this -> content [ $ section ] = array ( array ( self :: TK_SECTION , '[' . $ section . ']' ) ) ; } if ( ! $ foundValue ) { if ( $ key === null ) { $ this -> content [ $ section ] [ ] = array ( self :: TK_VALUE , $ name , $ value ) ; } else { if ( $ lastKey != - 1 ) { ++ $ lastKey ; } else { $ lastKey = 0 ; } $ this -> content [ $ section ] [ ] = array ( self :: TK_ARR_VALUE , $ name , $ value , $ lastKey ) ; } } $ this -> modified = true ; }
modify an option in the ini file. If the option doesn't exist,
it is created.

@param string $name    the name of the option to modify
@param string $value   the new value
@param string $section the section where to set the item. 0 is the global section
@param int    $key     for option which is an item of array, the key in the array. '' to just add a value in the array
modify an option in the ini file . If the option doesn t exist it is created .