Example of simple json multi-dimensional array construction using php-php Tutorial

Source: Internet
Author: User
Tags php database
This article mainly introduces php's simple construction of json multi-dimensional arrays, and analyzes the json format conversion operation skills of php database query results in the form of instances, for more information about how to construct a json multi-dimensional array in php, see the next article. This article analyzes the json format conversion operations of php database query results in the form of examples, for more information, see

This example describes how php constructs a json multi-dimensional array. We will share this with you for your reference. The details are as follows:

Php is actually very easy to construct a json multi-dimensional array.

The following php code serializes the query result array of mysqli to json:

$ 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 a detailed example of a simple json multi-dimensional array construction method using php. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.