What are some best practices for handling SQL query results in PHP arrays?

When handling SQL query results in PHP arrays, it is best practice to loop through the results and store them in an array for easier manipulation and access. This can be done by fetching each row from the query result and appending it to a PHP array.

// Assume $conn is the database connection object and $query is the SQL query
$result = $conn->query($query);

if ($result->num_rows > 0) {
    $data = array();

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

    // Now $data contains the query results in a PHP array
}