duanlian1978 2014-10-05 20:10
浏览 3

unset和json解码/编码

In my project i have 2d array, stores it in the DB as a string and processed as required. after reading from the database looks like :

[[19,44,69,99],[26,27,39,49,70,80],[20,30,40],[47,57,67],[84,85,86,87]]

after json_decode() looks like:

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
        )

)

and after json_encode():

[[19,44,69,99],[26,27,39,49,70,80],[20,30,40],[47,57,67],[84,85,86,87]]

But! If i use unset() when she is after json_decode() (somthing like this)

unset($Array[0][0]);

json_encode() will be return this:

[{"1":44,"2":69,"3":99},[26,27,39,49,70,80],[20,30,40],[47,57,67],[84,85,86,87]]

Change [] to {} why it happens and how to prevent it?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭