title: Encode nested JSON array in php
body: <p>I want to send nested JSON array.Which contain following format.</p>
  
  <pre><code>${"posts":[{
      "abc":"123",
      "xyz":"123",
      "pro":[{
          "name":"Brinjal",
          "qty":"500 gms"
      },
      {
          "name":"Brinjal",
          "qty":"500 gms"
      }] 
  }]
  }
  </code></pre>
  
  <p>Here is my php code:</p>
  
  <pre><code>$rows = $stmt-&gt;fetchAll();
  if ($rows) {
       $order["posts"]   = array();
      foreach ($rows as $row) {
          $post = array();
          $post["order_id"] =  $row["order_id"];
          $post["order_totalamount"] = $row["order_totalamount"];
          $post["address"] = $row["address"];
          $post["pincode"] = $row["pincode"];
          $post["delivery_timeslot"] = $row["delivery_timeslot"];
          $post["order_date"] = $row["order_date"];
          $query1= "query";
          $rows1 = $stmt-&gt;fetchAll();
          if ($rows1) {
              foreach ($rows1 as $row1) {                             
                  $query2= "query";
                  $rows2 = $stmt-&gt;fetchAll();
                  $post["product"]   = array();   
                  if ($rows2) {
                      $products = array();
                      foreach ($rows2 as $row2) {
                          $products["product_name"]=$row2["product_name"];
                          $products["prod_qty"] = $row2["product_minquantity"];
                      }
                      array_push($post["product"],$products);
                      echo json_encode($products);
                  }
  
              }
            }
          array_push($order["posts"], $post);
      }  
      echo json_encode($order);   
  }
  </code></pre>
  
  <p>From above code I got result:</p>
  
  <pre><code>$ {"posts":
      [{
      "order_id":"18",
      "order_totalamount":"40",
      "address":"2, Chetan Society, Vadodara",
      "pincode":"390023",
      "delivery_timeslot":"Zone wise delivery",
      "order_date":"2016-03-18 17:50:53",
      "product":[{"product_name":"Brinjal","prod_qty":"500 gms"}]
      }]
  }
  </code></pre>
  
  <p>But my actual product array is:</p>
  
  <pre><code>${"product_name":"Banana","prod_qty":"1 Kg"}{"product_name":"Brinjal","prod_qty":"500 gms"}
  </code></pre>
  
  <p>Kindly help out. I am stuck on it. tried a lot but did not get success.</p>