This article mainly introduces php's simple construction of json multi-dimensional arrays, and analyzes the json format conversion operation skills of php database query results in the form of instances, for more information about how to construct a json multi-dimensional array in php, see the next article. This article analyzes the json format conversion operations of php database query results in the form of examples, for more information, see
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:
The 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"}]}
The above is a detailed example of a simple json multi-dimensional array construction method using php. For more information, see other related articles in the first PHP community!