Home >Backend Development >PHP Tutorial >How to construct json multidimensional array in php
This article mainly introduces the method of php to simply construct jsonmulti-dimensional array, and analyzes the json format conversion operation skills of php database query results in the form of examples. Friends in need can refer to it
The example of this article describes how to simply construct a json multi-dimensional array in PHP. 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# that serializes the query result array of mysqli 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:
Copy code 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 How to construct json multidimensional array in php. For more information, please follow other related articles on the PHP Chinese website!