Jun 22 2009

PHP: Write to ini file array containing array

Category: PHPKristou Mehrez @ 1:27 am
public function write_ini_file($data, $path, $mode) {

		foreach ($data as $key => $item) {
			if (is_array($item)) {
				$content .= "\n[$key]\n";
				foreach ($item as $key2 => $item2) {
					if(is_array($item2)){
						foreach ($item2 as $key3 => $item3) {
							$content .= $key2."[] = \"".$item3."\"\n";
						}
					} else {
						$content .= "$key2 = \"$item2\"\n";
					}
				}
			} else {
				$content .= "$key = \"$item\"\n";
			}
		}

		if (!$handle = fopen($path, $mode)) {
			return false;
		}

		if (!fwrite($handle, $content)) {
			return false;
		}

		fclose($handle);
		return true;
	} // end write_ini_file()

Your Ad Here

Leave a Reply