MongoDB PHP using $ in with an array

I use MongoDB and PHP and try to make $ in based on the generated array.

When I specify the same array manually, it works, but when I create it, it returns any results with the same data.

Here is what I have:

$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))); 

I checked with

$ cursor-> info ()

And the elements in the array are the same.

Any ideas what I'm doing wrong?

Thanks!

+6
source share
1 answer

The data types are probably not the same. Try using var_dump () for the inline array and the specified array. You will probably see that they have numbers in a string, and others as prime integers.

+4
source

Source: https://habr.com/ru/post/912086/


All Articles