Phpjson_encode explanation _ PHP Tutorial

Source: Internet
Author: User
Phpjson_encode. Json_encode only supports UTF-8 format. The Copy code is as follows: $ arrayarray ([0] array ([sale_unit_detail_id] 13 [price] 740000 [geometric_lat] 51.5034 json_encode only supports UTF-8 format.

The code is as follows:


$ Array = array (
[0] => array ([sale_unit_detail_id] => 13 [price] => 740000 [geometric_lat] => 51.50348620 [geometric_lng] =>-0.01710900)
[1] => Array ([sale_unit_detail_id] => 27 [price] => 740000 [geometric_lat] => 51.50348620 [geometric_lng] =>-0.01710900)
);


The above php array json_encode is usually converted into a php array, which is like [[...] [...] but today I encountered a strange problem. when the length of my array reaches 142, it is converted
The format of {'0': {...}, '1': {...} is very strange. json_encode is a magic function.
This is a strange problem when json_encode in php is converted to a json string.

Compare the following two sections of code:

The code is as follows:


$ Menu [0] [0] = "title1 ";
$ Menu [0] [1] = "bar1 ";
$ Menu [0] [2] = "bar2 ";
$ Menu [1] [0] = 'tle2 ';
$ Menu [2] [0] = 'tle3 ';
Echo '& $ menu ='. json_encode ($ menu ).'&';


This will output: & $ menu = [["title1", "bar1", "bar2"], ["title2"], ["title3"] &

The code is as follows:


$ Menu [0] ["title"] = "title1 ";
$ Menu [0] ["bar1"] = "bar1 ";
$ Menu [0] ["bar2"] = "bar2 ";
$ Menu [1] [0] = 'tle2 ';
$ Menu [2] [0] = 'tle3 ';
Echo '& $ menu ='. json_encode ($ menu ).'&';


The output is: & $ menu = [{"title": "title1", "bar1": "bar1", "bar2": "bar2 "}, ["title2"], ["title3"] &

What does it mean? The problem is that {} and [], {} are objects, and [] are arrays !!!! The traversal method is different in non-php scenarios! Json_encode is amazing. it's amazing!

The http://www.bkjia.com/PHPjc/324404.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324404.htmlTechArticlejson_encode only supports UTF-8 format. the code is as follows: $ array = array ([0] = array ([sale_unit_detail_id] = 13 [price] = 740000 [geometric_lat] = 51. 5034...

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.