All pastes #477546 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-05-08 18:22 UTC
rendered paste body
	function json($data = array()) {
		header('Expires: 0');
		header('Pragma: no-cache');
		echo "[\n";
		$item_glue="";
		foreach($data as $item) {
			echo $item_glue."{\n";
			$field_glue = "";
			foreach($item as $key => $value) {
				echo $field_glue."\"$key\" : \"$value\"";
				$field_glue = ",\n";
			}
			echo "\n}";
			$item_glue = ",\n";
		}
		echo "\n]";
		exit();
	}
	function t() {
		$data[0] = array('item1' => 'valor1', 'item2' => 'valor2', 'item3' => 'valor3');
		$data[1] = array('itemA' => 'valorA', 'itemB' => 'valorB', 'itemC' => 'valorC');
		$this->json($data);

	}