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

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

怪我咯
Release: 2023-03-10 13:30:02
Original
1627 people have browsed it

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);
Copy after login

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"}]}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template