title: How to add loop data to json object in CI?
body: <p>I am trying to merge loop data to json object ,every time I am getting the last result of loop only ,so I declared that variable as a array ,its coming fine and I got my result but the format is not coming properly ,there is extra square brackets ,which I dont want ,because while parsing in front end ,its creating problem.</p>
  
  <p>Below i am providing my codes.</p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>{
  
    "status": "success",
    "statusReason": "Favouritelist",
    "result": {
      "Favouritelist": [
        [ //want to remove this square bracket
          {
            "branch_id": "1234",
            "branch_name": "avis1",
            "branch_image": "uploads/avis.png",
            "branch_gps": "12.9250,77.5938",
            "branch_address": "eredfdf",
            "branch_phone": "2147483647",
  
          }
        ],//want to remove this square bracket
        [//want to remove this square bracket
          {
            "branch_id": "1234",
            "branch_name": "avis1",
            "branch_image": "uploads/avis.png",
            "branch_gps": "12.9250,77.5938",
            "branch_address": "eredfdf",
            "branch_phone": "2147483647",
  
  
          }
        ]//want to remove this square bracket
      ]
    }
  }
  </code></pre>
  
  <p>My CI code</p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>foreach ($tempquery-&gt;result() as $res1){
           $car_id = $res1-&gt;car_id;  
  
         if(empty($timestamp)){
  
   $this-&gt;db-&gt;select("IFNULL(branch.branch_id,'') as branch_id,IFNULL(branch.name,'') as branch_name,IFNULL(branch.image,'') as branch_image,IFNULL(branch.gps,'') as branch_gps,IFNULL(branch.address,'')as branch_address,IFNULL(branch.phone,'')as branch_phone,(select IFNULL(avg(rating),0) from branch_rating where user_id='$user_id'  and delete_status ='false' )as branch_rating,IFNULL(car_id,'') as car_id,IFNULL(cars.name,'') as car_name,IFNULL(cars.image,'') as car_image,IFNULL(model,'') as model,IFNULL(price,'')as price,IFNULL(year,'')as year,IFNULL(type,'')as type,IFNULL(`no_of_seats`,'')as `no_of_seats`,IFNULL(`gear_type`,'') as `gear_type`,IFNULL(color,'') as color,insurance,status,IFNULL(description,'') as description,(select IFNULL(avg(rating),0) from car_rating where user_id='$user_id'  and delete_status ='false' )as car_rating,car_types.typename AS carType,cars.petrol_type,car_types.car_type_id,cars.delivery_charges,cars.services");
   $this-&gt;db-&gt;from("branch");
   $this-&gt;db-&gt;join("cars","branch.branch_id=cars.branch_id");
   $this-&gt;db-&gt;join('car_types', 'cars.car_type_id = car_types.car_type_id');
   $this-&gt;db-&gt;where("cars.car_id",$car_id);
   $this-&gt;db-&gt;where("branch.delete_status" , "false");
   $this-&gt;db-&gt;where("cars.delete_status" , "false");
  $car_details= $this-&gt;db-&gt;get();  
   $cdetail_new[]=$car_details-&gt;result(); ///added [] to mearge dat
  
  
             }
  
   Response::code_200("Favouritelist", array("Favouritelist" =&gt; $cdetail_new));  
  </code></pre>
  
  <p>Can any one suggest me ,where I am doing wrong..</p>
  
  <p>Thank you in ADV</p>