0

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!

1

1 Answer 1

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

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

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.