Reputation: 14270
I am trying to push a DB results to an array.
My goal is to make an array looks like the following
array('test1'=>2, 'test2'=>3);
I have a statement as following:
$results=DB::call($statement, $parameter);
and I need to use foreach
loop
foreach ($ids as $id){
$results[]=DB::call($statement, $id);
}
without a foreach
loop, my result array will be
array('test1'=>2, 'test2'=>3)
but with foreach
loop, my array will become 2 dimension
//loop twice in my case
array(
array(
'test1'=>2,
test2'=>3,
),
array(
'test3'=>4
'test4'=>5
)
)
Are there anyways to concatenate my results to create 1 dimension array only? Thanks for the help!
Upvotes: 0
Views: 26
Reputation: 1668
$results = array();
foreach ($ids as $id){
$results=array_merge($results,DB::call($statement, $id));
}
Upvotes: 1