脚本宝典收集整理的这篇文章主要介绍了php – codeigniter,result()与result_array(),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
通常我喜欢把我的结果作为数组,这就是为什么我主要使用result_array()
但我想知道我应该遵循哪种更好的方法,
哪一个在性能方面更有效?
这是我在codeigniter查询中讨论的示例
$query = $this->db->get(); $result = $query->result_array();
或者这应该是更好的方法?
$query = $this->db->get(); $result = $query->result();
现在我也在我的通用模型中使用result_array.
CodeIgniter的代码:
/** * Query result. Acts as a wrapper function for the following functions. * * @param string $type 'object','array' or a custom class name * @return array */ public function result($type = 'object') { if ($type === 'array') { return $this->result_array(); } elseif ($type === 'object') { return $this->result_object(); } else { return $this->custom_result_object($type); } }
数组在技术上更快,但它们不是对象.这取决于您希望在何处使用结果.大多数情况下,阵列就足够了.
以上是脚本宝典为你收集整理的php – codeigniter,result()与result_array()全部内容,希望文章能够帮你解决php – codeigniter,result()与result_array()所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。