1 回答
TA贡献1853条经验 获得超6个赞
使用 Doctrine 实现这一点可能不是您问题的答案,但可以解决您的问题。之后生成完整数组怎么样?
$arrValues = ['19', '4', '4', '18', '19'];
$objRequeteDoctrine = $this->getEntityManager()->createQueryBuilder()
->select('o')
->from('xxxxxx', 'o')
->where('o.id IN (:values)')
->andwhere('o.actif = 1')
->setParameter(':values', $arrValues );
$result = $objRequeteDoctrine->getQuery()->getResult();
// Get the object ids in a separate array to find their position in the result
$idsOnly = [];
foreach($result as $entity) {
$idsOnly[] = $entity->getId();
}
// Find the key of the object by id in the first result
$fullResult = [];
foreach ($arrValues as $id) {
$keyFound = array_search($id, $idsOnly);
if ($keyFound !== false) {
$fullResult[] = $result[$keyFound];
}
}
return $fullResult;
- 1 回答
- 0 关注
- 138 浏览
添加回答
举报