title: How can I validate the structure of my PHP arrays?
body: <p>Is there a function out there to make sure that any given array conforms to a particular structure? What I mean is that is has particular key names, perhaps particular types for values, and whatever nested structure. </p>
  
  <p>Right now I have a place where I want to make sure that the array getting past has certain keys, a couple holding a certain data type, and one sub-array with particular key names. I've done a lot of run-around because I was passing malformed arrays to it, and finally I'm at the point where I have a bunch of </p>
  
  <pre><code>if ( ! isset($arr['key1']) ) { .... }
  if ( ! isset($arr['key2']) ) { .... }
  if ( ! isset($arr['key3']) ) { .... }
  </code></pre>
  
  <p>I would have saved a lot of time and consternation if I could have checked that the array conformed to a particular structure beforehand. Ideally something like</p>
  
  <pre><code>$arrModel = array(
      'key1' =&gt; NULL ,
      'key2' =&gt; int ,
      'key3' =&gt; array(
          'key1' =&gt; NULL ,
          'key2' =&gt; NULL ,
        ),
  );
  
  if ( ! validate_array( $arrModel, $arrCandidate ) ) { ... }
  </code></pre>
  
  <p>So, the question I'm asking is, does this already exists, or do I write this myself? </p>