title: JSON TO CSV Conversion Notice: Array to string conversion in
body: <p>I am Trying to Convert JSON Data to CSV but it says that <strong>"Notice: Array to string conversion in D:\xampp\htdocs\api.pharmarack.com\Model\ConverterModel.php on line 427"</strong></p>
  
  <p><strong>MyJSON:</strong></p>
  
  <pre><code>[
      {
          "FirmId": "1",
          "OrderNo": "RP89",
          "PartyCode": "7026",
          "Status":"Processed",
          "InvoiceNo":"INV123",
          "InvoiceDate": "2017-12-02",
          "OrderDate": "2017-12-02 11:43:38.321813",
          "OrderDetails": [
              {
                  "Item": "ZAART 50 MGTAB",
                  "ItemDetailId": "22047",
                  "OrderedQty": "17",
                  "ProcessedQty":"17",
                  "ProcessedPTR":"24.5",
                  "ProcessedMRP":"30.5"
              },
              {
                  "Item": "RBTONE CAPS",
                  "ItemDetailId": "6091",
                  "OrderedQty": "10",
                  "ProcessedQty":"0",
                  "ProcessedPTR":"0",
                  "ProcessedMRP":"0"
              },
              {
                  "Item": "EBASIL 20MG",
                  "ItemDetailId": "80253",
                  "OrderedQty": "20",
                  "ProcessedQty":"15",
                  "ProcessedPTR":"45.0",
                  "ProcessedMRP":"50.0"
              }
          ]
      },
      {
          "FirmId": "1",
          "OrderNo": "RP88",
          "PartyCode": "7025",
          "Status":"Processed",
          "InvoiceNo":"INV123",
          "InvoiceDate": "2017-12-02",
          "OrderDate": "2017-12-02 11:31:13.307100",
          "OrderDetails": [
              {
                  "Item": "BG PROT L",
                  "ItemDetailId": "83570",
                  "OrderedQty": "20",
                  "ProcessedQty":"15",
                  "ProcessedPTR":"45.0",
                  "ProcessedMRP":"50.0"
              },
              {
                  "Item": "E ZINT LIQ",
                  "ItemDetailId": "88417",
                  "OrderedQty": "20",
                  "ProcessedQty":"15",
                  "ProcessedPTR":"45.0",
                  "ProcessedMRP":"50.0"
              },
              {
                  "Item": "A TO Z DROP",
                  "ItemDetailId": "98165",
                  "OrderedQty": "20",
                  "ProcessedQty":"15",
                  "ProcessedPTR":"45.0",
                  "ProcessedMRP":"50.0"
              }
          ]
      }
  ]
  </code></pre>
  
  <p><strong>PHP CODE:</strong></p>
  
  <pre><code>$fp = fopen($cfilename, 'w');
  $data = json_decode($json, true);
  $firstLineKeys = false;
  foreach ($data as $line) {
      if (empty($firstLineKeys)) {
          $firstLineKeys = array_keys($line);
          fputcsv($fp, $firstLineKeys);
          $firstLineKeys = array_flip($firstLineKeys);
      }
      $line_array = array($line['FirmId'], $line['OrderNo'], $line['PartyCode'], $line['Status'], $line['InvoiceNo'], $line['InvoiceDate'], $line['OrderDate']);
      foreach ($line['OrderDetails'] as $valueItem) {
          $item_array = array($value['Item'], $value['ItemDetailId'], $value['OrderedQty'], $value['ProcessedQty'], $value['ProcessedPTR'], $value['ProcessedMRP']);
          array_push($line_array, $item_array);
      }
      fputcsv($fp, $line_array);
  }
  
  fclose($fp);
  </code></pre>
  
  <p><strong>Expected Output:</strong>
  <a href="https://i.stack.imgur.com/mDTy0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mDTy0.png" alt="enter image description here"></a></p>