title: php - fputcsv Cannot use object of type stdClass as array
body: <p>I use post method to download csv using php with <code>fputcsv</code> when i using get method it works, but when using post it give me error, cannot use stdClass as array, people mention to use <code>json_decode</code> but i'm not sure wher to place it, </p>
  
  <p>I use laravel</p>
  
  <p>CODE :</p>
  
  <pre><code>public function csv (Request $request) {
  
      $storage_path = storage_path();
  
      $from = date($request-&gt;from_date);
      $to = date($request-&gt;to_date);
  
      $table = DB::table('registrations')-&gt;whereBetween('created_at', [$from, $to])-&gt;get();
  
  
  
      $filename = "data.csv";
      $handle = fopen('php://output', 'w+');
  
      fputcsv($handle, array('No', 'Nama', 'Nomor Telepon', 'Email', 'Tempat Tinggal',
          'Bank', 'Kartu Kredit', 'Rumah', 'Mobil', 'Luar Negeri', 'Penghasilan'));
  
      foreach($table as $row) {
              fputcsv($handle, array( $row['id'], $row['name'], $row['phonenumber'], $row['email'],
                              $row['umur'], $row['tempattinggal'],
                              $row['bank'], $row['kartukredit'], $row['rumah'],
                              $row['keluarnegeri'], $row['penghasilan'] ));
      }
  
      fclose($handle);
  
      $headers = array(
              'Content-Type' =&gt; 'text/csv',
      );
  
      return Response::download($filename, 'data.csv', $headers);
  }
  </code></pre>
  
  <p>the error happen to be on foreach,when i remove the for each , i can donwload the csv, but in badly format</p>