title: How to show php dynamic array data in c3js chart?
body: <p>I have multidimensional array(<code>$array</code>) like this,</p>
  
  <pre><code>{
  "2015-11-17": {
                  "department1":"0.5700",
                  "department3":"0.0000"
                },
  "2015-11-18": { 
                  "department1":"0.5700"
                },
  "2015-11-20": {
                  "department1":"0.0000"
                },
  "2015-11-23": {
                  "department1":"1.7100",
                  "department2":"1.7100",
                  "department3":"2.8500",
                }
    .
    .
    .
  }
  </code></pre>
  
  <p>This is a dynamic array and that data are get from database. All data are exists in <code>$array</code> variable. The above data are more than that. I just show a little, because the data are get from database.</p>
  
  <p>I want to show that data on c3js chart like this format,</p>
  
  <pre><code>json:[{
              "date": "2015-11-17",
              "department1": ""0.5700"",
              "department2": "0.0000",
              "department3": "0.0000",
              "department4": "0.0000",
          }],
  </code></pre>
  
  <p>And I need to show four department data for each date. </p>
  
  <p>In the array, you can see some day have one or two department. I want to add all four department for each day when I change above json format to show in chart.</p>
  
  <p>For example, in <code>2015-11-17</code>, it has department1 and 3. I want to add next department2 and 4 with '0' in this day.</p>
  
  <p>I want to add another department for each day just like that.</p>
  
  <p>When I try to change <code>$array</code> to above format, I don't get the correct result.
  Here is what I try,</p>
  
  <pre><code>&lt;div id='chart'&gt;&lt;/div&gt;
      &lt;script&gt;
              var chart = c3.generate({
                  bindto: '#chart',
                  data: {
                      x: 'date',
                      xFormat: '%Y-%m-%d',
                      json:[
                      &lt;?php 
                          for ($i = 0; $i &lt;  count($array); $i++) {
                              $key=key($array);
                              $val=$array[$key];
                              if ($val&lt;&gt; ' ') {
                                  foreach ($val as $k=&gt;$v) {
                      ?&gt;                  
                      {   
                          'date':&lt;?php echo $key?&gt;,
                          &lt;?php echo $k?&gt; : &lt;?php echo $v?&gt;,
                      },                  
  
                      &lt;?php
                                     }
                                 }
                               next($array);
                          }
                      ?&gt;],
  
                  },
                  legend: {
                      position: 'right',
                  },
                  line: {
                      width:0.5
                  },
                  axis: {
                      x: {
                          type: 'timeseries',
                          tick:{
                              format: '%Y-%m-%d',
                              rotate: 75,
                          },
                          label: {
                              text: 'Date',
                              position: 'outer-center'
                          }
                      }
                  },          
                  grid: {
                      y: {
                          show:true,
                      }
                  },
              });
      &lt;/script&gt;
  </code></pre>
  
  <p>So, now I have problem to show array data in chart. I'm very appreciate for any answer and suggestion. </p>
  
  <p>Here is the sample of dynamic chart image of what I want, <a href="https://i.stack.imgur.com/QpnAq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QpnAq.png" alt="sample chart"></a></p>