title: Pushing data to an multidimensional array JavaScript with PHP
body: <p>I have this JS <a href="https://github.com/rykdesjardins/js-calendar" rel="nofollow noreferrer">calendar library</a>, which I wanna fill up with dates from my MySQL database. </p>
  
  <p>This is looking like this:</p>
  
  <pre><code>    &lt;script&gt;
  
      var today = new Date();
      var matrix = {};
      var tmp;
  
      ';
  
      while($erg_termin = $res_termin_jahr -&gt; fetch())
      {
          echo '
          matrix['.$erg_termin-&gt;termin_beginn_jahr.'] = {};
          ';
      }
  
  
      while($erg_termin = $res_termin_monat -&gt; fetch())
      {
          echo '
          matrix['.$erg_termin-&gt;termin_beginn_jahr.']['.$erg_termin-&gt;termin_beginn_monat.'] = {};
          ';
      }
  
      while($erg_termin = $res_termin_tag -&gt; fetch())
      {
          echo '
          matrix['.$erg_termin-&gt;termin_beginn_jahr.']['.$erg_termin-&gt;termin_beginn_monat.']['.$erg_termin-&gt;termin_beginn_tag.'] = {};
          ';
      }
  
      while($erg_termin = $res_termin -&gt; fetch())
      {
          echo '
          matrix['.$erg_termin-&gt;termin_beginn_jahr.']['.$erg_termin-&gt;termin_beginn_monat.']['.$erg_termin-&gt;termin_beginn_tag.'].push({"displayname": "'.$erg_termin-&gt;termin_betreff.'"});
          ';
      }
  
      echo'
  
      console.log(matrix);
  
  
      &lt;/script&gt;
  </code></pre>
  
  <p>My result I get in the sourcecode is:</p>
  
  <pre><code>    &lt;script&gt;
  
      var today = new Date();
      var matrix = {};
      var tmp;
  
  
          matrix[2018] = {};
  
          matrix[2018][02] = {};
  
          matrix[2018][02][05] = {};
  
          matrix[2018][02][08] = {};
  
          matrix[2018][02][11] = {};
  
          matrix[2018][02][12] = {};
  
          matrix[2018][02][15] = {};
  
          matrix[2018][02][18] = {};
  
          matrix[2018][02][19] = {};
  
          matrix[2018][02][05].push({"displayname": "Wöchentliche Wiederholung"});
  
          matrix[2018][02][08].push({"displayname": "Wöchentliche Wiederholung"});
  
          matrix[2018][02][11].push({"displayname": "Wöchentliche Wiederholung"});
  
          matrix[2018][02][12].push({"displayname": "Wöchentliche Wiederholung"});
  
          matrix[2018][02][15].push({"displayname": "Wöchentliche Wiederholung"});
  
          matrix[2018][02][18].push({"displayname": "Wöchentliche Wiederholung"});
  
          matrix[2018][02][19].push({"displayname": "Wöchentliche Wiederholung"});
  
  
      console.log(matrix);
  
  
      &lt;/script&gt;
  </code></pre>
  
  <p>But here comes the problem. At the point of using the function <code>push</code> I get this error: <code>Uncaught TypeError: matrix[2018][2][5].push is not a function</code>.</p>
  
  <p>I guess the problem is that I want to push something to <code>matrix[2018][2][5]</code>. But I am not sure... How can I push values in JS to a multidimensional array?</p>
  
  <p>And because there will be much more dates, I cannot simply create an array for each date. The code needs to be dynamically!</p>
  
  <p>I would appreciate any kind of help!</p>
  
  <p>Kind regards</p>