PHP和codeigniter。如何返回数组对象,而不是简单的数组? [英] PHP and Codeigniter. How to return an array object and not plain array?
本文介绍了PHP和codeigniter。如何返回数组对象,而不是简单的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在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)
现在,它输出:
"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"
}
感恩所有输入!
推荐答案
只需使用:
array("email" => $result->row());
查看查询CI 文档和行()
:
该函数返回一个结果行。如果你的查询有多个行,它只返回的第一行。结果返回一个对象。
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.
这篇关于PHP和codeigniter。如何返回数组对象,而不是简单的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文