php将json转化为数组的方法:可以利用json_decode()函数来实现。该函数用于接收一个json格式的字符串并把它转换为php变量,如果参数$assoc为true,则函数返回array。
json_decode接受一个JSON格式的字符串并且把它转换为PHP变量,当该参数$assoc为TRUE时,将返回array,否则返回object。
(推荐教程:php图文教程)
语法:
json_decode(string $json[,bool $assoc = false[,int $depth = 512[,int $options = 0]]])
(视频教程推荐:php视频教程)
立即学习“PHP免费学习笔记(深入)”;
代码实现:
<?php // 在PHP变量中存储JSON数据 $json = '{"Peter":65,"Harry":80,"John":78,"Clark":90}'; var_dump(json_decode($json, true)); ?>
输出结果:
以上就是php如何将json转化为数组的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号