title: Dynamic Conditional String
body: <p>I have the code below taken partially inside a function:</p>
  
  <pre><code>$dynamic_comparison = '';  
  if(($from == '')&amp;&amp;($to == '')){
      $dynamic_comparison = 1;
  }else if(($from != '')&amp;&amp;($to != '')){
      $dynamic_comparison = '($row &gt;= $from) &amp;&amp; ($row &lt;= $to)';
  }else if(($from != '')&amp;&amp;($to == '')){
      $dynamic_comparison = '($row &gt;= $from)';
  }else if(($from == '')&amp;&amp;($to != '')){
      $dynamic_comparison = '($row &lt;= $to)';
  }
  </code></pre>
  
  <p><code>$form</code>, <code>$to</code> and <code>$row</code> are the parameters of the function.</p>
  
  <p>I want to evaluate <code>$dynamic_comparison</code> into something like this:</p>
  
  <pre><code>if($dynamic_comparison){
      //A bunch of code here...
  }
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>if(eval($dynamic_comparison)){
      //A bunch of code here...
  }
  </code></pre>
  
  <p>It throws an error. How to get this right?</p>