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条)

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)