PHP json_encode Strange problem Description _php tips

Source: Internet
Author: User
Json_encode only supports utf-8 format that's not much to say.
Copy Code code as follows:

$array = Array (
[0] => Array ([sale_unit_detail_id] => [Price] => 740000 [Geometric_lat] => 51.50348620 [GEOMETRIC_LNG] =& gt;-0.01710900)
[1] => Array ([sale_unit_detail_id] => [Price] => 740000 [Geometric_lat] => 51.50348620 [GEOMETRIC_LNG] =& Gt -0.01710900)
);

The above PHP array json_encode usually transforms the PHP array into a shape like [[...] [...]] Format, but today I came across a strange problem, and when my array length reached 142, I converted it to form
{' 0 ': {..}, ' 1 ': {...} ......} The format is very strange, json_encode a magical function
This is a very strange question when json_encode in PHP is an array of JSON strings.

Compare the following two pieces of code:
Copy Code code as follows:

$menu [0][0] = "Title1";
$menu [0][1] = "BAR1";
$menu [0][2] = "BAR2";
$menu [1][0] = ' title2 ';
$menu [2][0] = ' title3 ';
Echo ' & $menu = '. Json_encode ($menu). ' & ';

This will output:& $menu =[["Title1", "Bar1", "Bar2"],["Title2"],["Title3"]]&
Copy Code code as follows:

$menu [0]["title"] = "title1";
$menu [0]["bar1"] = "bar1";
$menu [0]["bar2"] = "bar2";
$menu [1][0] = ' title2 ';
$menu [2][0] = ' title3 ';
Echo ' & $menu = '. Json_encode ($menu). ' & ';

And this actually output:& $menu =[{"title": "Title1", "bar1": "Bar1", "bar2": "Bar2"},["Title2"],["Title3"]]&

What do you mean? The problem is that {} and [],{} are objects, [] are arrays!!!! In the case of non-PHP traversal when the method is not the same! Json_encode this thing is too magical, magical up let a person a bit depressed!

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.