欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php簡單構(gòu)造json多維數(shù)組的方法示例

 更新時(shí)間:2017年06月08日 10:13:58   作者:typ2004  
這篇文章主要介紹了php簡單構(gòu)造json多維數(shù)組的方法,結(jié)合實(shí)例形式分析了php數(shù)據(jù)庫查詢結(jié)果的json格式轉(zhuǎn)換操作技巧,需要的朋友可以參考下

本文實(shí)例講述了php簡單構(gòu)造json多維數(shù)組的方法。分享給大家供大家參考,具體如下:

php構(gòu)造json多維數(shù)組其實(shí)很簡單

下面列舉了將mysqli的查詢結(jié)果數(shù)組序列化為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);

輸出的字符串如下:

復(fù)制代碼 代碼如下:
{"result":"ok","msg":"login","fileinfo":[{"fileid":113,"name":"jishumingcheng","fujianname":"test.txt_test_20161005214223"},{"fileid":114,"name":"wodejishu","fujianname":"test.txt_test2_20161005230610"}]}

PS:這里再為大家推薦幾款比較實(shí)用的json在線工具供大家參考使用:

在線JSON代碼檢驗(yàn)、檢驗(yàn)、美化、格式化工具:
http://tools.jb51.net/code/json

JSON在線格式化工具:
http://tools.jb51.net/code/jsonformat

在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson

json代碼在線格式化/美化/壓縮/編輯/轉(zhuǎn)換工具:
http://tools.jb51.net/code/jsoncodeformat

C語言風(fēng)格/HTML/CSS/json代碼格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP中json格式數(shù)據(jù)操作技巧匯總》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《PHP基本語法入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論