Are there any best practices for iterating through database query results and storing them in arrays in PHP?

When iterating through database query results in PHP and storing them in arrays, it is important to use a loop to fetch each row from the result set and store the data in an array. This can be achieved by using a while loop to fetch each row as an associative array and then pushing it into another array for storage.

// Assuming $stmt is the prepared statement object
$result = $stmt->get_result();
$data = array();

while ($row = $result->fetch_assoc()) {
    $data[] = $row;
}

// Now $data contains all the rows from the query result stored in an array