2012-12-14 46 views
0

我正試圖將數據庫結果推送到數組。將數據庫結果返回給數組問題

我的目標是做一個數組看起來就像下面

array('test1'=>2, 'test2'=>3); 

我有一個聲明如下:

$results=DB::call($statement, $parameter); 

,我需要使用foreach循環

foreach ($ids as $id){ 

    $results[]=DB::call($statement, $id); 

} 

沒有foreach循環,我的結果數組將爲

array('test1'=>2, 'test2'=>3) 

foreach循環,我的陣列將成爲2維

//loop twice in my case 

array(
    array(
     'test1'=>2, 
     test2'=>3,   
    ), 
    array(
     'test3'=>4  
     'test4'=>5  
    )  
) 

是否有反正來連接我的成績只創建1個維數組?謝謝您的幫助!

+0

'array_merge' ... – Wrikken

+0

http://stackoverflow.com/search?q=MERGE+ARRAY – Ydhem

回答

1
$results = array();  
foreach ($ids as $id){ 

    $results=array_merge($results,DB::call($statement, $id)); 

}