Convert array to have specific keys which are integers
<p>I would like to validate that an array has and only has "a", "b", and "c" as associate keys, and that the values are either integers or either NULL or 0 (what ever is easier).</p>

<p>For instance, <code>array('a'=&gt;123,'b'=&gt;'abc', 'd'=&gt;321)</code> should be converted to <code>array('a'=&gt;123,'b'=&gt;0, 'c'=&gt;0)</code>.</p>

<p>I can do something like the following, but it is a little difficult to read, and will become big if I don't just have 3 elements but 300.</p>

<pre><code>$newArr=array(
 'a'=&gt;(isset($arr['a']))?(int)$arr['a']:0,
 'b'=&gt;(isset($arr['b']))?(int)$arr['b']:0,
 'c'=&gt;(isset($arr['c']))?(int)$arr['c']:0
);
</code></pre>

<p>Another option is something like the following:</p>

<pre><code>$newArr=array();
foreach (array('a','b','c') as $key)
{
 $newArr[$key]=(isset($arr[$key]))?(int)$arr[$key]:0;
}
</code></pre>

<p>I guess this works good enough, however, am curious whether there is some slick array converting function that I don't know about that would be better.  Any advice?  Thanks</p>
