This article mainly introduces the method of simply constructing json multi-dimensional arrays in PHP, and analyzes the JSON format conversion operation skills of PHP database query results in the form of examples. Friends in need can refer to the following
The examples in this article describe PHP simple method to construct json multidimensional array. Share it with everyone for your reference, the details are as follows:
It is actually very simple to construct a json multi-dimensional array in php
The following is a list of the php code to serialize the mysqli query result array into json as follows
$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 the detailed content of Example of how to simply construct a json multidimensional array using php. For more information, please follow other related articles on the PHP Chinese website!