在我的项目中,我有2d数组,将其作为字符串存储在数据库中并根据需要进行处理。 从数据库中读取后看起来像:
[[19,44,69,99],[26,27,39,49,70,80],[20,30,40],[47,57,67],[84,85,86 ,87]]
在json_decode()之后看起来像:
Array
(
[0] => Array
(
[0] => 19
[1] => 44
[2] => 69
[3] => 99
)
[1] => Array
(
[0] => 26
[1] => 27
[2] => 39
[3] => 49
[4] => 70
[5] => 80
)
[2] => Array
(
[0] => 20
[1] => 30
[2] => 40
)
[3] => Array
(
[0] => 47
[1] => 57
[2] => 67
)
[4] => Array
(
[0] => 84
[1] => 85
[2] => 86
[3] => 87
)
)
和json_encode()之后:
[[19,44,69,99],[26,27,39,49,70,80],[20,30,40],[47,57,67],[84,85,86 ,87]]
但是! 如果我在json_decode()之后使用unset()(这样的话)
unset($Array[0][0]);
json_encode()将返回此:
[{ “1”:44 “2”:69, “3”:99},[26,27,39,49,70,80],[20,30,40],[47,57 ,67],[84,85,86,87]]
将[]更改为{} 为什么会发生以及如何预防?