All pastes #256563 Raw Edit

Untitled

public text v1 · immutable
#256563 ·published 2006-11-24 11:42 UTC
rendered paste body
function array_2_ini($array, $fname = "")
{
	if(strlen($fname) == 0)
		$fname = time() . ".ini";

	$num_sections = count($array);
	$section_names = array_keys($array);
	$output = "; header thingy\n\n";	// our lil header ;)

	for($x = 0; $x < $num_sections; $x++)
	{
		$this_name = $section_names[$x];
		$output .= "[" . $this_name . "]\n";

		for($b = 0; $b < count($array[$this_name]); $b++)
		{
			$key_names = array_keys($array[$this_name]);
			$output .= $key_names[$b] . "=" . $array[$this_name][$key_names[$b]]."\n";	
		}
	}

	//-- set the file contents
	$handle = fopen($fname, "w");
	fwrite($handle, $output, strlen($output));
	fclose($handle);

	return true;
}