Home > Backend Development > PHP Tutorial > Need to pay attention to json_encode after php array_unique_PHP tutorial

Need to pay attention to json_encode after php array_unique_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:33:03
Original
768 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:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template