Codeigniter, when result_array () returns a single or multidimensional array?

When returning $ query-> result_array ();
Someday I get several single arrays, for example:

Array ( [user_id] => 32 [username] => johnd [cat_id] => 7 ) Array ( [user_id] => 33 [username] => Janed [cat_id] => 6 ) 

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

This has something to do with the request, is there a specific criterion for this?

+4
source share
1 answer

$query->result_array() always returns you a 2D array (if the database does not return any results, then returns an empty array).

It returns an array of result arrays. Each result array contains these row fields.

Docs: http://ellislab.com/codeigniter/user-guide/database/results.html

+2
source

All Articles