手机
当前位置:查字典教程网 >编程开发 >php教程 >php array_unique之后json_encode需要注意
php array_unique之后json_encode需要注意
摘要:例如:array_unique(array(1,1,2));他的结果是array(2){[0]=>int(1)[2]=>int(2)}这就不...

例如:array_unique(array(1, 1, 2));

他的结果是

array(2) {

[0]=>

int(1)

[2]=>

int(2)

}

这就不是numeric数组了,直接做json_encode,会输出一个json对象,而不是数组

{"0":1,"2":2}

如果这时候页面上js需要的是[1,2]这种数组数据格式,就有可能会产生错误

此时应该在array_unique之后,在做一个array_values

这样:array_values(array_unique(array(1, 1, 2)));

结果就是[1,2]

【php array_unique之后json_encode需要注意】相关文章:

typecho插件编写教程(四):插件挂载

Content-type 的说明

example1.php

发挥语言的威力--融合PHP与ASP

用PHP生成自己的LOG文件

GD输出汉字的函数的分析

php使用指定编码导出mysql数据到csv文件的方法

php实现paypal 授权登录

php+oracle 分页类

php输出全球各个时区列表的方法

精品推荐
分类导航