2011-06-21 29 views
0

使用DB或ORM從一個字段檢索結果的最佳方法是什麼?Kohana 3(ORM或DB)返回單個字段

例如,我需要一個用戶的朋友id數組將它們傳遞給其他函數。我現在這樣做:

$friends_ids = $this->friends->find_all()->as_array('id', 'name'); 

$friends = array(); 

foreach ($friends_ids as $k => $v) 
{ 
    array_push($friends, $k); 
} 

也許有更好的辦法嗎?

回答

1
$friends = $this->friends->find_all()->as_array(NULL, 'id'); 
+0

好的。我想這是最好的解決方案 – Fenec

相關問題