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

Multiple find() array parameters

Hi,

how can i set an array to the find function? The parameter $wantedUsersId, is an array of id's -> 1,2,3,4,5,....

$users = Users::find($wantedUsersId);

Thx

Stefan

edited Nov '15

I think it's supported since 2.0.4

https://blog.phalcon.io/post/phalcon-2-0-4-released

https://docs.phalcon.io/en/latest/reference/models.html

$wantedUsersId = [[0] => 35, [2] => 78]; //keys must be numbered from zero:
$users = Users::find(
    array(
        'id IN ({ids:array})',
        'bind' => array(
            'ids' => $wantedUsersId
        )
    )
);


59.9k
edited Nov '15

Hello Jimmy,

Yes it works :-))

This also works:

  $users = Users::query()
           ->inWhere('id', $blackbookUsersId)
           ->execute();

Rgds

Stefan