dongwang3066 2011-08-28 11:28
浏览 93
已采纳

PHP和Codeigniter。 如何返回数组对象而不是普通数组?

In Codeigniter I am creating an array and returning it to the user. I am creating the array like this (result is the return form a DB query):

array("email" => $result)

Right now it outputs:

"email": [
    {
        "id": "629",
        "desc": "0000",
        "value_1": "0000",
        "value_2": null,
        "value_3": null,
        "value_4": null,
        "privacy": "0"
    }
]

So $result is an array that contains a single object. How can I make $result contain just the object instead? Like this:

"email": {
    "id": "628",
    "desc": "THIS IS IT",
    "value_1": "THIS IS IT2",
    "value_2": null,
    "value_3": null,
    "value_4": null,
    "privacy": "0"
}

Thankful for all input!

  • 写回答

3条回答 默认 最新

  • douba1904 2011-08-28 11:32
    关注

    Just use:

    array("email" => $result->row());
    

    See the CI documentation on queries and row():

    This function returns a single result row. If your query has more than one row, it returns only the first row. The result is returned as an object.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?