MongoDB PHP将$ in与数组一起使用 [英] MongoDB PHP using $in with array
本文介绍了MongoDB PHP将$ in与数组一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用MongoDB和PHP,并尝试基于生成的数组进行$ in操作.
I'm using MongoDB and PHP and trying to do a $in based on a generated array.
当我手动指定相同的数组时,它可以工作,但是当我构建它时,它返回具有相同数据的任何结果.
When I specify the same array manually, it works, but when I build it, it return any results with the same data.
我有什么:
$settings = array();
foreach($items as $item) {
$settings[] = $item['id'];
}
//Settings is the same as this
$setting2 = array(1,2,3,4,5,6,7,8);
//This returns no results
$cursor = $collection->find(array('status' => 0, 'sid' => array('$in' => $settings)));
//This does return results
$cursor = $collection->find(array('status' => 0, 'sid' => array('$in' => $setting2)));
我已经使用
$ cursor-> info()
$cursor->info()
与数组中的项目相同.
有什么想法我在做什么错吗?
Any ideas what I'm doing wrong?
谢谢!
推荐答案
数字的数据类型可能不相同.尝试在构建的数组和指定的数组上使用var_dump().您可能会看到其中一个以数字形式存在于字符串中,而另一个以简单的整数形式存在.
It's likely that the data types of the numbers are not the same. Try using var_dump() on the built array, and the specified array. You'll probably see one has them as numbers in a string, and the other as simple integers.
这篇关于MongoDB PHP将$ in与数组一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文