Need to pay attention to json_encode after php array_unique_PHP tutorial

WBOY
Release: 2016-07-21 15:33:03
Original
729 people have browsed it

For example: array_unique(array(1, 1, 2));
The result is
array(2) {
[0]=>
int(1)
[2 ]=>
int(2)
}

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

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

At this time, it should be in array_unique After that, make an array_values ​​
like this: array_values(array_unique(array(1, 1, 2)));

The result is [1,2]

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322698.htmlTechArticleFor example: array_unique(array(1, 1, 2)); His result is array(2) { [ 0]= int(1) [2]= int(2) } This is not a numeric array. Doing json_encode directly will output a json object instead of...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template