Result有一个可选的$type参数,用于决定返回的结果类型.默认情况下($type =“object”),它返回一个对象(result_object()).它可以设置为“array”,然后它将返回一个结果数组,相当于caling 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);
}
}
数组在技术上更快,但它们不是对象.这取决于您希望在何处使用结果.大多数情况下,阵列就足够了.