title: MySQLi get results and create key value array
body: <p>I want to build an array with key-value pairs of MySqli query. What I have so far overwrites array's entries:</p>
  
  <pre><code>$array = array();
  
      while($row = mysqli_fetch_array($result))
      {
          $difference = abs($base - $row["sql_number"]);
          $array = [$difference =&gt; $row["sql_number"]];
          $bar = each($array);
          print_r($bar);
      }
  
      echo count($array);
      ksort($array);
      echo count($array);
  
      foreach ($array as $key =&gt; $value) {             
          echo "Key: ".$key;
          echo "Value: ". $value;
      }
  </code></pre>
  
  <p><code>print_r($bar);</code> prints the key-value pairs correct but I am convinced it is because it just prints the latest entry from the <code>mysqli_fetch_array($result)</code> and the previous entries are overwriten. 
  I want to create such an array then sort it with <code>ksort</code> by the key value.</p>