Json_encode after phparray_unique _ PHP Tutorial

Source: Internet
Author: User
Pay attention to json_encode after phparray_unique. For example: array_unique (array (, 2); the result is array (2) {[0] int (1) [2] int (2 )} this is not a numeric array. if json_encode is directly used, a json object is output instead of array_unique (array (1, 1, 2 ));
The result is
Array (2 ){
[0] =>
Int (1)
[2] =>
Int (2)
}

This is not a numeric array. json_encode is directly used to output a json object instead of an array.
{"0": 1, "2": 2}

If the js on the page needs an array data format of [1, 2] At this time, an error may occur.

After array_unique, create an array_values
In this way, array_values (array_unique (array (1, 1, 2 )));

The result is [1, 2].

Struct (array (1, 1, 2); the result is array (2) {[0] = int (1) [2] = int (2 )} this is not a numeric array. json_encode is directly used to output a json object instead...

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.