結果有一個可選的$type
參數,該參數決定返回哪種類型的結果。默認情況下($type = "object"
),它返回一個對象(result_object()
)。它可以設置爲"array"
,然後它將返回一個結果數組,相當於計算result_array()
。第三個版本接受一個用作結果對象的自定義類。
從笨代碼:
/**
* 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);
}
}
陣列在技術上更快,但他們都沒有對象。這取決於你想在哪裏使用結果。大多數時候,陣列就足夠了。