Home  >  Article  >  Backend Development  >  Example of how to simply construct a json multidimensional array using php

Example of how to simply construct a json multidimensional array using php

怪我咯
怪我咯Original
2017-06-16 10:08:431605browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn