应该后端发送数据2D数组或数组对象来查看

时间:2016-10-21 10:16:16

标签: php arrays json model-view-controller

$data = $sql->fetchAll(PDO::FETCH_ASSOC);

//2D array (when mysql fetchAll, it came out like this)
Array
(
    [0] => Array
        (
            [id] => 20,
            [title] => "testing1",
            [time] => 1471936066
        )

    [1] => Array
        (
            [id] => 18,
            [title] => "testing2",
            [time] => 1467780284
        )
);

//array object
Array(
        {
            "id" : 20,
            "title" : "testing1",
            "time" : 1471936066
        },


        {
            "id" : 18
            "title" : "testing2",
            "time" : 1467780284
        }
);

我有一个关于发送数据格式到后端查看的问题(有时它需要是JS的JSON字符串,但不是所有时间)

我应该发送2D数组来查看还是应该将数据转换为数组对象并将其发送到视图文件?

0 个答案:

没有答案