fetch()){$fileinfo..._php json 二维数组">
赞
踩
本文实例讲述了php简单构造json多维数组的方法。分享给大家供大家参考,具体如下:
php构造json多维数组其实很简单
下面列举了将mysqli的查询结果数组序列化为json的php代码如下
$res['result'] = "ok";
$res['msg'] = 'login';
$res['fileinfo'] = array();
while($stmt->fetch()){
$fileinfo['fileid'] = $fileid;
$fileinfo['name'] = $name;
$fileinfo['fujianname'] = $fujianname;
array_push($res['fileinfo'], $fileinfo);
}
echo json_encode($res);
输出的字符串如下:
{"result":"ok","msg":"login","fileinfo":[{"fileid":113,"name":"jishumingcheng","fujianname":"test.txt_test_20161005214223"},{"fileid":114,"name":"wodejishu","fujianname":"test.txt_test2_20161005230610"}]}
PS:这里再为大家推荐几款比较实用的json在线工具供大家参考使用:
希望本文所述对大家PHP程序设计有所帮助。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。