title: Conversion sql select query to array for json encode
body: <p>I want to make $sql to $employees which is array for <code>print</code> <code>json_encode($employees);</code></p>
  
  <pre><code>$sql = "SELECT name,title,salary  FROM persons";
  </code></pre>
  
  <p>I have already tried with this code but result was right</p>
  
  <pre><code>$employees = array();
  while($r = mysqli_fetch_assoc($sql)) {
       $employees['name'] = $r['name'];
       $employees['title']=$r['title'];
       $employees['salary']=$r['salary'];
  
  }
  print json_encode($employees);
  </code></pre>
  
  <p>Please help to find output as like following this
  Output:</p>
  
  <pre><code>$employees = 
      array(
              array
              (
              "name" =&gt; "Jack",
              "title" =&gt; "Magager",
              "salary" =&gt; "$60,000",
              ),
  
              array
              (
              "name" =&gt; "Joe",
              "title" =&gt; "Developer",
              "salary" =&gt; "$50,000",
              ),
  
              array
              (
              "name" =&gt; "Susan",
              "title" =&gt; "Marketer",
              "salary" =&gt; "$50,000",
              )
          );
  </code></pre>