title: Converting a multi-dimensional php array into a JSON array of objects
body: <p>I need to create a multi-dimensional array in php and want to use it in a jQuery script as a JSON array of objects;</p>
  
  <p>The required output in the jQuery script should look like this:</p>
  
  <pre><code>data = [
          { Month:'April', Comms:1000, Fees:200, Gains: 200},
          { Month:'May',   Comms:1200, Fees:300, Gains: 300}
          ]   
  </code></pre>
  
  <p>Currently my php arrays are generated as follow:</p>
  
  <pre><code>    $data1[] = array(
          'Month' =&gt; 'April',
          'Comms' =&gt; 1000,
          'Fees'  =&gt; 200,
          'Gains' =&gt; 200      
      );      
      $data2[] = array(
          'Month' =&gt; 'May',
          'Comms' =&gt; 1200,
          'Fees'  =&gt; 300,
          'Gains' =&gt; 300      
      );
  
      echo json_encode($data);
  </code></pre>
  
  <p>My question is how to combine data1 and data2 into the data array in the json_encode php function which will produce the required jQuery JSON array of objects? </p>
  
  <p>I do have the values of the different array fields and can create data1 and data2 in a different way, so the data is flexible and I can combine them in any other way which will produce the data array which will output them in the required JSON format.</p>
  
  <p>Any help will be highly appreciated, I have seen question regarding this subject but none which address the issue I am facing.</p>