title: Array within Array on duplicate id or other reord
body: <p>I am writing webs services in PHP for a mobile app and have to put some data in get query for order details service.
  I am getting the below response with my query when i encoded into json.</p>
  
  <pre><code>{
    "status": 101,
    "message": "Success",
    "result": [
      {
        "order_id": "38",
        "order_product_id": "49",
        "product_id": "377",
        "product_name": "Pineapple Cake 2 Kg Eggless + Free Surprise Gift",
        "option_name": "Delivery Time",
        "option_value": "4:00am to 6:00am",
        "model": "Cake B22",
        "quantity": "1"
  
      },
      {
        "order_id": "38",
        "order_product_id": "49",
        "product_id": "377",
        "product_name": "Pineapple Cake 2 Kg Eggless + Free Surprise Gift",
        "option_name": "Message For Cake",
        "option_value": "Second order first product",
        "model": "Cake B22",
        "quantity": "1"
      },
      {
        "order_id": "38",
        "order_product_id": "50",
        "product_id": "339",
        "product_name": "Pineapple Cake 1 Kg + Free Surprise Gift",
        "option_name": "Make it Eggless",
        "option_value": "No",
        "model": "Cake A7",
        "quantity": "1"
      },
      {
        "order_id": "38",
        "order_product_id": "50",
        "product_id": "339",
        "product_name": "Pineapple Cake 1 Kg + Free Surprise Gift",
        "option_name": "Delivery Time",
        "option_value": "4:00am to 6:00am",
        "model": "Cake A7",
        "quantity": "1"
      },
      {
        "order_id": "38",
        "order_product_id": "50",
        "product_id": "339",
        "product_name": "Pineapple Cake 1 Kg + Free Surprise Gift",
        "option_name": "Message For Cake",
        "option_value": "second order 2nd cake",
        "model": "Cake A7",
        "quantity": "1"
      }
    ]
  }
  </code></pre>
  
  <p>Which i am getting through sql query </p>
  
  <pre><code>$strSQL = "SEletc * ........";
  
      $objQuery = mysql_query($strSQL);
      $intNumField = mysql_num_fields($objQuery);
      $resultArray = array();
       $data_ok = false;
      while($obResult = mysql_fetch_array($objQuery))
      {
          $arrCol = array();
  
          $data_ok = false;
          for($i=0;$i&lt;$intNumField;$i++)
          {
              $arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
          }
          array_push($resultArray,$arrCol);
  $data_ok = true;
      }
      if($data_ok) {
       $response["status"] = 101;
         $response["message"] = "Success";
           $response["result"] = $resultArray;
       echo json_encode($response);
  }
  else
  {
   $response["status"] = 100;
    $response["message"] = "No category exist in database";
  
   echo json_encode($response);
  }
      mysql_close($objConnect);
  </code></pre>
  
  <p>What I want is like this </p>
  
  <pre><code>{
    "status": 101,
    "message": "Success",
    "result": [
      {
        "order_id": "38",
        "order_product_id": "49",
        "product_id": "377",
        "product_name": "Pineapple Cake 2 Kg Eggless + Free Surprise Gift",
        "result2": [
          {
            "option_name": "Delivery Time",
            "option_value": "4:00am to 6:00am",
  
          },
          {
            "option_name": "Message For Cake",
            "option_value": "Second order first product",
  
          }
        ],
        "model": "Cake B22",
        "quantity": "1"
      },
      {
        "order_id": "38",
        "order_product_id": "50",
        "product_id": "339",
        "product_name": "Pineapple Cake 1 Kg + Free Surprise Gift",
        "result2": [
          {
            "option_name": "Make it Eggless",
            "option_value": "No",
  
          },
          {
            "option_name": "Delivery Time",
            "option_value": "4:00am to 6:00am",
  
          },
          {
            "option_name": "Message For Cake",
            "option_value": "Second order first product",
  
          }
        ],
        "model": "Cake A7",
        "quantity": "1"
      }
    ]
  }
  </code></pre>
  
  <p>Thank you in advance
  Priyanka </p>