Mick Mick - 4 years ago 243
PHP Question

Doctrine Query Builder using Array

I have an array of id:

Id_array; //array(2) { [0]=> int(9) [1]=> int(10) }

I simply want to select the users using Id_array;
I managed to do this when I don't have an array but just an integer:

$query = $em->createQuery('SELECT u FROM Users u WHERE u.id = ?1');
$query->setParameter(1, 9); // I tested the value 9 here
$users = $query->getResult();

How can I fetch all the users that correspond to Id_array?

Answer Source

Or without the query builder:

$query = $em->createQuery('SELECT u FROM Users u WHERE u.id IN (:id)');
$query->setParameter('id', array(1, 9));
$users = $query->getResult();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download