小兔网

1、PHP数组数据写入JSON文件

<?php
// 生成一个PHP数组
$data = array();
$data['name'] = 'admin';
$data['pwd'] = '123456';

// 把PHP数组转成JSON字符串
$json_string = json_encode($data);

// 写入文件
file_put_contents('user.json', $json_string);
?>

2、将JSON文件的数据读取到PHP变量

<?php
// 从文件中读取数据到PHP变量
$json_string = file_get_contents('user.json');

// 把JSON字符串转成PHP数组
$data = json_decode($json_string, true);

// 显示出来看看
var_dump($data);
?>

 

PHP怎么把JSON转换成数组?

php如何将json字符串转成数据变量

PHP函数json_encode()如何将数据变量转成json

PHP函数simplexml_load_string如何读取xml文件

PHP语言json数据写入到json文件,读取json文件

php读取本地json文件