How to write a function that checks if a variable is defined and is a number?
<p>In the past when I needed to check if a variable was set <strong>and also</strong> a number, I would do:</p>

<pre><code>if( isset($_GET['var']) &amp;&amp; is_numeric($_GET['var']) )
</code></pre>

<p>But I think that's kind of ugly, especially when I need to check a bunch of variables in the same if statement, so I made a function:</p>

<pre><code>function setAndNum($var)
{
    if(isset($var) &amp;&amp; is_numeric($var))
        return 1;
    else
        return 0;
}
</code></pre>

<p>The problem is that when I pass an undefined variable to the function, like this (supposing the variable in the GET array is undefined):</p>

<pre><code>if( setAndNum($_GET['var']) )
</code></pre>

<p>I get the php error:</p>

<blockquote>
  <p>Notice: Undefined index: ...</p>
</blockquote>

<p>So the whole purpose of the function is basically defeated (or half the purpose, at least ;) ). </p>

<p>One thing that confuses me is how the isset() function works, and why I can pass an undefined variable to it but not to my own function?</p>

<p>Is it possible to make my setAndNum() function work? </p>
