您可以使用json_encode
功能。
以下是示例代码,
$result = MysqL_query(your sql here);
$data = array();
while ($row = MysqL_fetch_assoc($result)) {
// Generate the output in desired format
$data = array(
'cols' => ....
'rows' => ....
'p' => ...
);
}
$json_data = json_encode($data);
file_put_contents('your_json_file.json', $json_data);