best practice to make string int and check if string is not int
<p>I have the following code:</p>

<pre><code>&lt;?php

function s2int($pinned_id) { 
$action="aaa";
if ( $action &amp;&amp; is_numeric($pinned_id) &amp;&amp; (float)$pinned_id==(int)$pinned_id) {
   /**
   * @param [string] $action is setted
   * @param [int/string as int] $pinned_id is setted
   */
echo "-chekpoint- $pinned_id\n";
    $pinned_id = (int)$pinned_id;
} 
else { echo "-passpoint- $pinned_id\n";}
return $pinned_id;
}

echo s2int("000010")."\n";
echo s2int(10.00001)."\n";
echo s2int(10)."\n";
echo s2int("10")."\n";
echo s2int("0")."\n";
echo s2int("a")."\n";
echo s2int("a10")."\n";
echo s2int("10a")."\n";
echo s2int("0x1A")."\n";
echo s2int("-100")."\n";
</code></pre>

<p>OUTPUT:</p>

<pre><code>-chekpoint- 000010
10
-passpoint- 10.00001
10.00001
-chekpoint- 10
10
-chekpoint- 10
10
-chekpoint- 0
0
-passpoint- a
a
-passpoint- a10
a10
-passpoint- 10a
10a
-chekpoint- 0x1A
0
-chekpoint- -100
-100
</code></pre>

<p>EXPECTED OUTPUT:</p>

<pre><code>-chekpoint- 000010
10
-passpoint- 10.00001
10.00001
-chekpoint- 10
10
-chekpoint- 10
10
-chekpoint- 0
0
-passpoint- a
a
-passpoint- a10
a10
-passpoint- 10a
10a
-passpoint- 0x1A
0x1A
-chekpoint- -100
-100
</code></pre>

<p>what is best practice to make s2int to return correct (int) variable and make action if variable can't be converted to  (int)   (as you see result unexpected if input is hexadecimal ?</p>

<p><a href="http://codepad.org/lN84HKzV" rel="nofollow">http://codepad.org/lN84HKzV</a></p>
