Home  >  Article  >  Backend Development  >  How to construct json multidimensional array in php

How to construct json multidimensional array in php

陈政宽~
陈政宽~Original
2017-06-28 13:37:491747browse

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!

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