Php simple json multi-dimensional array method example, json multi-dimensional array example
This example describes how php constructs a json multi-dimensional array. We will share this with you for your reference. The details are as follows:
Php is actually very easy to construct a json multi-dimensional array.
The following php code serializes the query result array of mysqli to json:
$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);
The output string is as follows:
Copy codeThe Code is as follows: {"result": "OK", "msg": "login", "fileinfo": [{"fileid": 113, "name": "jishumingcheng ", "fujianname": "test.txt _ test_20161005214223" },{ "fileid": 114, "name": "wodejishu", "fujianname": "test.txt _ test2_20161005230610"}]}
PS: Here are some useful json online tools for your reference:
Online JSON code verification, validation, beautification, and formatting tools:
Http://tools.jb51.net/code/json
JSONOnline formatting tool:
Http://tools.jb51.net/code/jsonformat
Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson
JsonCode Online formatting/beautification/compression/editing/conversion tools:
Http://tools.jb51.net/code/jsoncodeformat
C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json