1

The following code are written in CodeIgniter, as a method of my model.

function get_user () {
 $result = $this->db->get('users_table')->result();
}

the $result is the resulting array of objects as the result of running database query, what is the best way to convert $result in an array?

4
  • $result is actually already an array, you can foreach($result as $k=>$v){ echo $v['columnName']; Commented Mar 4, 2016 at 8:46
  • 1
    You can confirm the above comment by doing a var_dump($result); and see if it starts off with a array ( ...... Commented Mar 4, 2016 at 8:47
  • Have a look at the CodeIgniter documentation, this explains query results. Commented Mar 4, 2016 at 8:52
  • try result_array() instead of result()....... Commented Mar 4, 2016 at 10:53

6 Answers 6

2

Try with result_array() function instead of result()

Sign up to request clarification or add additional context in comments.

Comments

2

use

result_array();

function get_user () {
   $result = $this->db->get('users_table')->result_array();
}

Comments

2

eater you can try

function get_user () {
   $result = $this->db->get('users_table')->result_array();
}

or just use the basic

function get_user () {
 $result = (array)$this->db->get('users_table')->result();
}

Comments

1

Use Codeigniter's function result_array()

Comments

0

try this.

function get_user () {
   $result = $this->db->get('users_table')->result_array();
}

Comments

0

Codeigniter is convert into array in provided the function in result_array()

Example : $rs = $this->db->get('table')->result_array();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.