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()
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.
Docs: http://ellislab.com/codeigniter/user-guide/database/results.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With