title: PHP JSON API - detect data types of return values
body: <p>im working on a <code>PHP JSON API</code> which returnes <code>json_encoded</code> multidimensional arrays.
  Due to the fact, that <code>PHP</code> is a weak typed language - i have some problems with the returned data types on the client side as e.g. integers are returned as strings.</p>
  <p><strong>Example of a response</strong></p>
  <p><em><strong>Before json encode</strong></em></p>
  <pre><code>array() {
    [&quot;users&quot;]=&gt;
    array() {
      [&quot;id&quot;]=&gt;
      string(3) &quot;983&quot;
      [&quot;email&quot;]=&gt;
      string(28) &quot;xxx.xxx@xxx.xxx&quot;
      [&quot;username&quot;]=&gt;
      string(8) &quot;xxx&quot;
      [&quot;verified&quot;]=&gt;
      string(1) &quot;2&quot;
      [&quot;tutorial_completed&quot;]=&gt;
      string(1) &quot;1&quot;
    }
    [&quot;companies&quot;]=&gt;
    array() {
      [&quot;id&quot;]=&gt;
      string(3) &quot;170&quot;
      [&quot;name&quot;]=&gt;
      string(0) &quot;xxx&quot;
      [&quot;trusted&quot;]=&gt;
      string(1) &quot;1&quot;
    }
  }
  </code></pre>
  <p><em><strong>After json encode</strong></em></p>
  <pre><code>data: {
     users: {
       id: &quot;983&quot;,
       email: &quot;xxx@xxx.xxx&quot;,
       username: &quot;xxx&quot;,
       verified: &quot;2&quot;,
       tutorial_completed: &quot;1&quot;,
     },
     companies: {
       id: &quot;170&quot;,
       name: &quot;xxx&quot;,    
       trusted: &quot;1&quot;,
     }
  }
  </code></pre>
  <p>I'm getting the data from a <code>MySQL table</code>.
  The values are basically taken as they are.</p>
  <p><strong>One solution, that works</strong> is checking each key and then cast the numeric values by <code>intval()</code> or <code>floatval()</code> - but this would mean an enourmous effort for bigger arrays and the solution lacks in flexibility.</p>
  <p>Is their a smooth way to automatically detects if the data type can be a numeric value as well and if so, cast it?</p>