Codeigniter什么时候result_array()返回一维或多维数组? [英] Codeigniter when does result_array() return a single or multi dimensional array?
问题描述
返回$ query-> result_array();
有时我会得到多个单个数组,如下所示:
On returning $query->result_array();
Sometime I get multiple single arrays like this:
Array
(
[user_id] => 32
[username] => johnd
[cat_id] => 7
)
Array
(
[user_id] => 33
[username] => Janed
[cat_id] => 6
)
有时候我会得到这样的多维数组:
While sometimes i get multidimensional arrays like this:
Array
(
[0] => Array
(
[user_id] => 33
[username] => Janed
[cat_id] => 6
)
[1] => Array
(
[user_id] => 32
[username] => Johnd
[cat_id] => 7
)
)
是否与查询有关,是否有特定原因?
Is it something to do with the query, is there a specificreason for this?
推荐答案
$ query-> result_array()
始终返回一个2D数组(除非数据库不返回结果,然后它返回一个空数组)。
$query->result_array()
always returns you a 2D array (unless the database returns no results, then it returns an empty array).
它返回一个结果数组数组。每个结果数组都包含该行的字段。
It returns you an array of "result" arrays. Each result array contains that row's fields.
文档: http://ellislab.com/codeigniter/user-guide/database/results.html
这篇关于Codeigniter什么时候result_array()返回一维或多维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!