title: Encoding json with php
body: <p>So here the thing: </p>
  
  <p>I am developing a backend (php) that connects with Microsoft SQL Server with android application to be the user interface. </p>
  
  <p>However, I am facing a problem when it comes to encoding json with php.</p>
  
  <p>It is more than fair to say that I am a beginner in php.</p>
  
  <p>This is my code:</p>
  
  <pre><code>$result = sqlsrv_query( $conn, 'select * from table1');
   $row = sqlsrv_fetch_array($result);
   $array = array();
  while($row =sqlsrv_fetch_array($result))
  {
      $array[]=$row;
  }
  echo json_encode(array("data"=&gt;array_values($array)));
  </code></pre>
  
  <p>So the table actually has nothing so far: 
  just two attributes: name and age</p>
  
  <p>The problem here is that the return is being as follows:</p>
  
  <pre><code>{"data":[{"0":"Miriana","name":"Miriana","1":null,"age":null},{"0":"Luke","name":"Luke","1":null,"age":null},{"0":"Sara","name":"Sara","1":null,"age":null},{"0":"Fuss","name":"Fuss","1":20,"age":20}]}
  </code></pre>
  
  <p>There is always a number preceding the values with a value then the real key and a value.</p>
  
  <p>For example:</p>
  
  <pre><code>"0":"Miriana"
   "1":null
  </code></pre>
  
  <p>Thanks so much for anyone who would check this out.</p>
  
  <p>**I checked those links:
  <a href="https://stackoverflow.com/questions/27493015/decode-json-with-php-not-working">Decode json With PHP not working</a>
  <a href="https://stackoverflow.com/questions/6964403/parsing-json-with-php">Parsing JSON with PHP</a>
  <a href="https://stackoverflow.com/questions/27485217/encoding-json-with-php-issues-with-array">Encoding JSON with PHP issues with array</a>
  **</p>