Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I want to convert a string to php code.

$criteria = "\"department\" => array('\$in' => array(\"IT\"))";

My actual Mongodb query is this,

$collection->find(array("name" => $a, "department" => array('$in' => array("IT")));

But what I need is, query should be based on criteria..

$collection->find(array("name" => $a, $criteria);

But this doesn't seem to work for me.

I even tried eval($criteria) and then tried it. Negative result.

Where am I going wrong? Any help would be appreciated.

share|improve this question
    
Where is your $criteria string being created? You generally wouldn't want to be passing in a user-provided string to eval as code. – Stennie Nov 8 '12 at 17:15
    
You should look at $regex and $in, see this - $regex and $in – nathansizemore Nov 14 '12 at 17:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.