title: Generating Custom JSON in PHP
body: <p>I have a database query which needs to encoded in json format in PHP,I need the data to be encoded in particular format.</p>
  
  <p>The format I want is</p>
  
  <pre><code>{
      "Car tyre Showroom":{"ABCD":"1234567","CDEF":"90000000","PPPP":"1000000"},
      "Bike tyre Showroom":{"AFGH":"32124235","AAAAA":"9111111111"},
      "Car Driving School":{"AMNB ":"45565778"},
      "Car battery shop":{"PLQA":"4235346456"}
  }
  </code></pre>
  
  <p>But I am getting in the format of</p>
  
  <pre><code>    {
          "Car tyre Showroom":{"PPPP":"1000000"}
      },{
          "Bike tyre Showroom":{"AAAAA":"9111111111"}
      },{
          "Car Driving School":{"AMNB ":"45565778"}
      },{
          "Car battery shop":{"PLQA":"4235346456"}
      }
  </code></pre>
  
  <p>My database query is:</p>
  
  <pre><code> $query = "select S.SpecificCategoryName,A.* from specificcategories S,areaspecificdealers A where A.SpecificCategoryId=S.SpecificCategoryId and A.LocationCode=(Select LocationCode from arealist where LocationName='".$location."')"; 
  </code></pre>
  
  <p>And I have encoded json this way,</p>
  
  <pre><code> for($col = 0; $col &lt; count($result); $col++)
  {
  
  
  
  
          $values[$result[$col]['SpecificCategoryName']]= array($result[$col]['ClientName']=&gt;$result[$col]['PhoneNumber']);
  
  
  }
  </code></pre>
  
  <p>echo json_encode($values);</p>
  
  <p>Kindly help how to encode data in the above way.</p>