How can the use of loops in PHP be optimized to handle fetching and processing multiple entries from a MySQL query result?

When fetching and processing multiple entries from a MySQL query result in PHP, it is important to optimize the use of loops to minimize the number of queries sent to the database. One way to achieve this is by fetching all the results at once and then processing them within a loop. This can be done using the `fetch_all()` method to retrieve all rows from the result set in a single call.

// Assuming $result is the MySQL query result
$rows = $result->fetch_all(MYSQLI_ASSOC);

foreach ($rows as $row) {
    // Process each row here
}