title: php check to see if variable is integer
body: <p>Is there a nicer way to do this?</p>
  
  <pre><code>if( $_POST['id'] != (integer)$_POST['id'] )
      echo 'not a integer';
  </code></pre>
  
  <p>I've tried</p>
  
  <pre><code>if( !is_int($_POST['id']) )
  </code></pre>
  
  <p>But <code>is_int()</code> doesn't work for some reason.</p>
  
  <p>My form looks like this</p>
  
  <pre><code>&lt;form method="post"&gt;
     &lt;input type="text" name="id"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I've researched <code>is_int()</code>, and it seems that if </p>
  
  <pre><code>is_int('23'); // would return false (not what I want)
  is_int(23);   // would return true
  </code></pre>
  
  <p>I've also tried <code>is_numeric()</code></p>
  
  <pre><code>is_numeric('23'); // return true
  is_numeric(23); // return true
  is_numeric('23.3'); // also returns true (not what I want)
  </code></pre>
  
  <p><strike>it seems that the only way to do this is:</strike> [this is a bad way, do not do it, see note below]</p>
  
  <pre><code>if( '23' == (integer)'23' ) // return true
  if( 23 == (integer)23 ) // return true
  if( 23.3 == (integer)23.3 ) // return false
  if( '23.3' == (integer)'23.3') // return false
  </code></pre>
  
  <p>But is there a function to do the above ?</p>
  
  <hr>
  
  <p>Just to clarify, I want the following results</p>
  
  <pre><code>23     // return true
  '23'   // return true
  22.3   // return false
  '23.3' // return false
  </code></pre>
  
  <hr>
  
  <p><strong>Note: I just figured out my previous solution that I presented will return true for all strings. (thanks redreggae)</strong></p>
  
  <pre><code>$var = 'hello';
  if( $var != (integer)$var )
      echo 'not a integer';
  
  // will return true! So this doesn't work either.
  </code></pre>
  
  <hr>
  
  <p>This is not a duplicate of <a href="https://stackoverflow.com/questions/6416763">Checking if a variable is an integer in PHP</a>, because my requirements/definitions of integer is different than theres.</p>