title: php check if isset and value = 0
body: <p>I am using the CodeIgniter framework to create my web services. I have an optional parameter that I want to set its value according to:-</p>
  
  <ul>
  <li>if it exists and has value 0, var2 = a</li>
  <li>else var2 = b</li>
  </ul>
  
  <p><strong>Method 1</strong></p>
  
  <pre><code>    $foo = $this-&gt;post('foo');
  
      if(isset($foo) &amp;&amp; $foo == 0) {
          $var2 = 'a';
      } else {
          $var2 = 'b';
      }
  </code></pre>
  
  <p><strong>Method 2</strong></p>
  
  <pre><code>    $foo = $this-&gt;post('foo');
  
      if(isset($foo)) {
          if ($foo == 0)
              $var2 = 'a';
          else
              $var2 = 'b';
      } else {
          $var2 = 'b';
      }
  </code></pre>
  
  <p>Both methods are returning <code>$var2 = 'a'</code> when I do not send in <code>foo</code>.</p>