title: Force to add array into single element of JSON in PHP integrated to plugin
body: <p>This question is based on the existing post at <a href="https://stackoverflow.com/questions/56504201/force-to-add-array-into-single-element-of-json-in-php">Force to add array into single element of JSON in PHP</a></p>
  
  <p>Now i need to add some custom function into 3rd party WordPress export plugin to make my desired JSON output. Since i have some limit knowledge on the PHP and array, so would like some help from your guys</p>
  
  <p>Two issue still need to fix for this code:</p>
  
  <p>1) order_item for postid=32081 not able to show all items(total 3 order item), currently only last one is show e.g. ugs=A0003</p>
  
  <p>2)Need to include array(or square bracket) to all the parameter under order_item</p>
  
  <p>existing function to export json</p>
  
  <pre><code>function woo_ce_export_dataset_override_order( $output = null, $export_type = null) {
  
      global $export;
      $orders = woo_ce_get_orders( 'order', $export-&gt;args );
  
      if( !empty( $orders ) ) {
          if( !empty( $export-&gt;fields ) ) {
  
              $export-&gt;total_columns = $size = count( $export-&gt;columns );
  
              $output = [
                  "transaction_date" =&gt; date('Ymd'),
                  "neworders" =&gt; []    
              ];
  
              if( !empty( $export-&gt;fields ) ) {
                  foreach( $orders as $order ) {
  
                      $args = $export-&gt;args;
  
                      $order = woo_ce_get_order_data( $order, 'order', $args, array_keys( $export-&gt;fields ) );
  
                      foreach( array_keys( $export-&gt;fields ) as $key =&gt; $field ) {
                          if( isset( $order-&gt;$field ) &amp;&amp; isset( $export-&gt;columns[$key] ) ) {
  
                              $post[ $export-&gt;columns[$key] ] = $order-&gt;$field;
                          }
                      }
  
                      if( !empty( $order-&gt;order_items ) ) {
                          foreach( $order-&gt;order_items as $order_item ) {
                              foreach( array_keys( $export-&gt;fields ) as $key =&gt; $field ) {
                                  if( isset( $order_item-&gt;$field ) &amp;&amp; isset( $export-&gt;columns[$key] ) ) {
  
                                      $post['order_item'][ $export-&gt;columns[$key] ] = $order_item-&gt;$field;
                                  }
                              }
                          }
                      }
                      $output['neworders'][] = $post;
                  }
              }
          }
      }
      return array($output);
  } 
  </code></pre>
  
  <p>what i get from output</p>
  
  <pre><code>[
      {
          "transaction_date": "20190609",
          "neworders": [
              {
                  "postid": 32081,
                  "label": "22615",
                  "address": "19 RUE",
                  "postcode": "27450",
                  "order_item": {
                      "ugs": "A0003",
                      "qty": "6"
                  }
              },
              {
                  "postid": 32082,
                  "label": "22617",
                  "address": "2 impas",
                  "postcode": "12300",
                  "order_item": {
                      "ugs": "B0002",
                      "qty": "1"
                  }
              }
          ]
      }
  ]
  </code></pre>
  
  <p>what i need</p>
  
  <pre><code>[
      {
          "transaction_date": "20190609",
          "neworders": [
              {
                  "postid": 32081,
                  "label": "22615",
                  "address": "19 RUE",
                  "postcode": "27450",
                  "order_item": [ 
                      {
                          "ugs": "A0001",
                          "qty": "3"
                      },
                      {
                          "ugs": "A0002",
                          "qty": "1"
                      },
                      {
                          "ugs": "A0003",
                          "qty": "6"
                      }
                 ]
              },
              {
                  "postid": 32082,
                  "label": "22617",
                  "address": "2 impas",
                  "postcode": "12300",
                  "order_item": [
                     {
                        "ugs": "B0001",
                        "qty": "1"
                    }
                  ]
              }
          ]
      }
  ]
  </code></pre>