protected function build( array $data, $depth = 0, $prevKey = null ) {
		$valueOutput = "";
		$arrayOutput = "";

		if( $depth > 2 ) {
			throw new ExceededMaxDepthException("Max INI Depth of 2 Exceeded");
		}

		$position = 0;
		foreach( $data as $key => $val ) {
			if( $this->skipNullValues && $val === null ) {
				continue;
			} elseif( is_array($val) ) {
				if( $depth == 0 ) {
					$arrayOutput .= "\n[{$key}]\n";
				}
				$arrayOutput .= $this->build($val, $depth + 1, $key);
			} else {
				$valStr = $this->escape($val);
				if( $depth > 1 ) {

					if( $key !== $position ) {
						if( ctype_digit((string)$key) ) {
							$position = $key;
						}

						$valueOutput .= "{$prevKey}[{$key}] = {$valStr}\n";
					} else {
						$valueOutput .= "{$prevKey}[] = {$valStr}\n";
					}

					$position++;
				} else {
					$valueOutput .= "{$key} = {$valStr}\n";
				}
			}
		}

		$output = "{$valueOutput}\n{$arrayOutput}";

		return $depth ? ltrim($output) : trim($output);
	}
protected function build( array $data, $depth = 0, $prevKey = null ) {
		$valueOutput = "";
		$arrayOutput = "";

		if( $depth > 2 ) {
			throw new ExceededMaxDepthException("Max INI Depth of 2 Exceeded");
		}

		$position = 0;
		foreach( $data as $key => $val ) {
			if( $this->skipNullValues && $val === null ) {
				continue;
			} elseif( is_array($val) ) {
				if( $depth == 0 ) {
					$arrayOutput .= "\n[{$key}]\n";
				}
				$arrayOutput .= $this->build($val, $depth + 1, $key);
			} else {
				$valStr = $this->escape($val);
				if( $depth > 1 ) {

					if( $key !== $position ) {
						if( ctype_digit((string)$key) ) {
							$position = $key;
						}

						$valueOutput .= "{$prevKey}[{$key}] = {$valStr}\n";
					} else {
						$valueOutput .= "{$prevKey}[] = {$valStr}\n";
					}

					$position++;
				} else {
					$valueOutput .= "{$key} = {$valStr}\n";
				}
			}
		}

		$output = "{$valueOutput}\n{$arrayOutput}";

		return $depth ? ltrim($output) : trim($output);
	}
protected function build ( array $ data , $ depth = 0 , $ prevKey = null ) { $ valueOutput = "" ; $ arrayOutput = "" ; if ( $ depth > 2 ) { throw new ExceededMaxDepthException ( "Max INI Depth of 2 Exceeded" ) ; } $ position = 0 ; foreach ( $ data as $ key => $ val ) { if ( $ this -> skipNullValues && $ val === null ) { continue ; } elseif ( is_array ( $ val ) ) { if ( $ depth == 0 ) { $ arrayOutput .= "\n[{$key}]\n" ; } $ arrayOutput .= $ this -> build ( $ val , $ depth + 1 , $ key ) ; } else { $ valStr = $ this -> escape ( $ val ) ; if ( $ depth > 1 ) { if ( $ key !== $ position ) { if ( ctype_digit ( ( string ) $ key ) ) { $ position = $ key ; } $ valueOutput .= "{$prevKey}[{$key}] = {$valStr}\n" ; } else { $ valueOutput .= "{$prevKey}[] = {$valStr}\n" ; } $ position ++ ; } else { $ valueOutput .= "{$key} = {$valStr}\n" ; } } } $ output = "{$valueOutput}\n{$arrayOutput}" ; return $ depth ? ltrim ( $ output ) : trim ( $ output ) ; }
Recursive build function

@param array                 $data
@param int                   $depth
@param null|int|float|string $prevKey
@return string
@throws ExceededMaxDepthException
Recursive build function