title: How to check data validity based on expected type?
body: <p>I need to validate some values received from an HTTP request (typically from $_POST and $_GET) against their related expected type.</p>
  
  <p>Here is how possible parameters are defined : </p>
  
  <pre><code>$defs = [ 
  'op'       =&gt; [ 'type' =&gt; 'string' ],
  'out'      =&gt; [ 'type' =&gt; 'integer'],
  'throttle' =&gt; [ 'type' =&gt; 'double']
  ];
  </code></pre>
  
  <p>PHP offers the filter_var() function which actually sanitize the values but don't tell if format is valid or not.</p>
  
  <p>Is there another way to achieve this without having to write a regex for each possible type (string, boolean, integer, float, double, array) ?</p>