CodeIgniter: Returning data as an object vs array

There are functions to return your data as an object:

$query = $this->db->query("YOUR QUERY"); if ($query->num_rows() > 0) { foreach ($query->result() as $row) { echo $row->title; echo $row->name; echo $row->body; } } 

Or an array:

 $query = $this->db->query("YOUR QUERY"); foreach ($query->result_array() as $row) { echo $row['title']; echo $row['name']; echo $row['body']; } 

I always returned my data as arrays, but when does it happen that returning an β€œobject” is preferable?

+4
source share

Source: https://habr.com/ru/post/1496874/


All Articles