row_array()和result_array()之间有什么区别?
if ($variable) { return $result->row_array(); } else { return $result->result_array(); }
从
documentation开始,row_array返回单个结果,result_array返回多个结果(通常用于循环).
文档中的示例:
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']; }