Fetch an array result set using a mysqli wrapper class I have a PHP class:

&lt;?php
//connectionclass.php
class connectionclass{
public $conn;
public $warn;
public $err;

function __construct(){
  $this-&gt;connect();
}

private function connect(){
  $this-&gt;conn = @ new mysqli('localhost', 'sever_user', 'user_password');
    if ($this-&gt;conn-&gt;connect_error) {
      $this-&gt;conn = FALSE;
      $this-&gt;warn = '&lt;br /&gt;Failed to connect database! Please try again later';
     }
}

public function get_data($qry){
 $result = $this-&gt;conn-&gt;query($qry);
    if ($result-&gt;num_rows&gt;=1) {
        while($row=$result-&gt;fetch_assoc()){
           $rows[] = $row;
        }
        return $rows;
    } else {
        $this-&gt;err = $this-&gt;conn-&gt;error;
        return FALSE;
    }
}

}
?&gt;


and a PHP page:

&lt;?php
//login.php
include('/include/connectionclass.php');
$db = new connectionclass();

$query = "SELECT * FROM USERS WHERE user_country='India'";
$data = $db-&gt;get_data($query);
  $rownum = count($data);
  for($i=0;$i&lt;$rownum;$i++){
     echo $data[$i]['name'].'- '.$data[$i]['age'].'&lt;br /&gt;';
  }
?&gt;


Is there any idea for an easier way to iterate $data in the PHP page?
First, you can use mysqli_result::fetch_all in your connectionclass::get_data() instead of manually looping and building the result array.

Second, you can use foreach to easily iterate through results