I am passing an array as a string in parameter to an api in php like this:
http://xx.xx.xx.xx/api.php?query="array(done = 1)"
In my api file, I have used this array to hit a mongodb query:
$query = $_REQUEST['query'];
$cursor = $collection->find($query);
But this didn't work. When I hard-coded array(done = 1)
into the find
query, it seems to work fine.
if (array('done' => 1) == $query) {
echo "Y";
}
else {
echo "N";
}
The above code prints N
. So I guess it's because $query
is being passed as a string.
PS: I also tried json_encode, json_decode and unserialize but it didn't work. I might be doing omething wrong here.