title: JSON Array Export to CSV in PHP
body: <p>I'm trying to export to csv, a JSON with the following format:
  <code></p>
  
  <pre><code>$json_file2{
              "errors":
                      {
                      "code":0,
                      "text":""
                      },
              "results":
                      {
                      "resultado":
                      [
                          {
                          "referencia":"00000",
                          "cantidad":"24",
                          "cantidad_proveedor":null,
                          "delivery_time":"delivery time 2 days"
                          },
                          {
                          "referencia":"00001",
                          "cantidad":"24",
                          "cantidad_proveedor":"48",
                          "delivery_time":""
                          },
                          {
                          "referencia":"00098_1",
                          "cantidad":"96",
                          "cantidad_proveedor":null,
                          "delivery_time":"delivery time 4 days"
                          }
                      ]
                  }
              }
  </code></pre>
  
  <p></code></p>
  
  <p>I need to export to csv
  <code></p>
  
  <pre><code>"referencia":"00000",
  "cantidad":"24",
  "cantidad_proveedor":null,
  "delivery_time":"delivery time 2 days"
  </code></pre>
  
  <p></code></p>
  
  <p>in this format:
  <code></p>
  
  <pre><code>"00000","24",null,"delivery time 2 days"
  "00001","24","48",""
  "00098_1","96",null,"delivery time 4 days"
  ......
  </code></pre>
  
  <p></code></p>
  
  <p>I try to do as I am learning</p>
  
  <p><code></p>
  
  <pre><code>$decoded = json_decode($json_file2);
  $comments = $decoded-&gt;data[0]-&gt;results-&gt;resultado;
  $fp = fopen('stock2.csv', 'w');
  foreach($comments as $comment){
     fputcsv($fp,$comment);
  }
  </code></pre>
  
  <p></code>
  but always it gives me error foreach:
  <strong>Warning: Invalid argument supplied for foreach()</strong></p>
  
  <p>Where am I doing wrong?
  Tanks</p>