Duke Yin's Technology database

Php write a json file

<?php
// 生成一个PHP数组
$data = array();
$data[0] = array('1','stuff','2');
$data[1] = array('2','john','4');
// 把PHP数组转成JSON字符串
$json_string = json_encode($data);
// 写入文件
file_put_contents('test.json', $json_string);
?>

读取

<?php
// 从文件中读取数据到PHP变量
$json_string = file_get_contents('test.json');
// 把JSON字符串转成PHP数组
$data = json_decode($json_string, true);
?>

引用关闭,但你能发布评论.

评论

标注 * 的为必填项。