title: How to change the output of the JSON array in an object in PHP?
body: <p>I have an issue regarding the API JSON output. I am getting stuck into JSON output when in a loop, it is making its own index when i am forcing the array format to change into the index array.</p>
  
  <p>PHP Code:</p>
  
  <pre><code>$sql = "SELECT name,fname,address FROM user_management";
  $array = array();
  
  $result = $conn-&gt;query($sql);
  $i=1;
  
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      $array=["message"=&gt;"success"];
      while($row = $result-&gt;fetch_assoc()) {
  
      $array[] = ["Hello" =&gt; $row];
  
   } 
  
  } 
  else 
  {
      echo "0 results";
  }
   //echo implode(',', $array);
   // Take output array glue it with the
  echo json_encode($array);
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>I am getting the response as:</p>
  
  <pre><code>{
    "message": "success",
    "0": {
      "Hello": {
        "name": "harjot",
        "fname": "tejinder",
        "address": "noida"
      }
    },
    "1": {
      "Hello": {
        "name": "regret",
        "fname": "egegrregeger",
        "address": "gegreg"
      }
    },
    "2": {
      "Hello": {
        "name": "harjot1",
        "fname": "harjot2",
        "address": "noida"
      }
    },
    "3": {
      "Hello": {
        "name": "har",
        "fname": "har1",
        "address": "Punjab"
      }
    }
  }
  </code></pre>
  
  <p>I want the response as without the 0,1,2,3 that array is making on its own.Is there a way to access the index of an arrays?</p>
  
  <p><strong>Expected output:</strong></p>
  
  <pre><code>{   "message": "success",
      "Hello": {
        "name": "harjot",
        "fname": "tejinder",
        "address": "noida"   },
      "Hello1": {
        "name": "regret",
        "fname": "egegrregeger",
        "address": "gegreg"   },
      "Hello2": {
        "name": "harjot1",
        "fname": "harjot2",
        "address": "noida"   },
      "Hello3": {
        "name": "har",
        "fname": "har1",
        "address": "Punjab"
      }   
  }
  </code></pre>