Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How can i combine the result obtained through find() method over several ids?

i ran a for loop over an array (ids) to find record s from db...how can i combine them into an array of single object.

       $ids=array(1,2,3,4);
       foreach($ids as $id){
       data[]=Model::findFirstById($id)
       }


99.6k
Accepted
answer
edited Dec '16
$data = Model::find([
    'conditions' => 'id IN ({ids:array})',
    'bind' => [
        'ids' => [1,2,3,4]
    ]
]);