php中数组转json的规则是:当没有指定索引(0~n)时会转换为json数组,而指定了索引会转换为json对象。
PHP的数组在转JSON的时候,如果索引连续,则转成数组。...如果索引不连续,则会转成对象
1、没有指定索引的情况:
$attr = array("a","b","c","d","e");
转换为json:
["a","b","c","d","e"]
2、有指定索引的情况...{
"a": "a",
"b": "b",
"c": "c",
"d": "d",
"e": "e"
}
3、默认索引,但是索引不连续,也会转成对象...【unset() 做数组处理时会使默认索引丢失,可以使用array_values()初始化索引】
$attr = array("0"=>"a","1"=>"b","3"=>"c","4"=>"d","5