Difference between row_array and result_array
result_array()
Returns the query result as a pure array. Typically you’ll use this in a
foreach
loop.row_array()
Returns a single result row. If your query has more than one row, it returns only the first row.
Identical to therow()
method, except it returns an array.
From the documentation, row_array
returns a single result and result_array
returns multiple results (usually for use in a loop).
Examples from the documentation:
Result_array:
$query = $this->db->query("YOUR QUERY");
foreach ($query->result_array() as $row)
{
echo $row['title'];
echo $row['name'];
echo $row['body'];
}
Row_array:
$query = $this->db->query("YOUR QUERY");
if ($query->num_rows() > 0)
{
$row = $query->row_array();
echo $row['title'];
echo $row['name'];
echo $row['body'];
}