Php simple json multi-dimensional array method example, json multi-dimensional array example

Source: Internet
Author: User
Tags array example

Php simple json multi-dimensional array method example, json multi-dimensional array example

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:
Copy codeThe 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"}]}

PS: Here are some useful json online tools for your reference:

Online JSON code verification, validation, beautification, and formatting tools:
Http://tools.jb51.net/code/json

JSONOnline formatting tool:
Http://tools.jb51.net/code/jsonformat

Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson

JsonCode Online formatting/beautification/compression/editing/conversion tools:
Http://tools.jb51.net/code/jsoncodeformat

C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json

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.