PHP constructs a JSON multidimensional array method

Source: Internet
Author: User
This article mainly introduced the PHP simple construction JSON multidimensional array method, combined with the instance form analysis PHP database query result JSON format conversion operation skill, needs the friend can refer to the next

This article describes a simple way to construct a JSON multidimensional array in PHP. Share to everyone for your reference, as follows:

PHP constructs JSON multidimensional arrays is actually very simple

The following is a list of PHP code that serializes the MYSQLI query result array 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 the Code code as follows:

{"Result": "OK", "MSG": "Login", "FileInfo": [{"Fileid": 113, "name": "Jishumingcheng", "Fujianname": "Test.txt_test_ 20161005214223 "},{" Fileid ":", "name": "Wodejishu", "Fujianname": "test.txt_test2_20161005230610"}]}

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.