我正在使用以下代码:
foreach ($record as $doc)
{
$groupIds[] = $doc['groupId'];
}
$gpids = "'".implode("','",array_unique($groupIds))."'";
$collection5 = $db->chat;
$cursor = $collection5->find(array('groupId' => array('$in' => array($gpids))));
foreach($cursor as $res)
{
print_r($res);
}
但不会有结果。请帮帮我。
这是因为您的$gpids
是一个字符串,您最终会在$in
查询中放入一个元素数组。这应该有效:
$collection5->find(array('groupId' => array('$in' => array_unique($groupIds))));