We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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)
       }


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