In the context of PHP, what is the significance of using GROUP BY in SQL queries when dealing with data aggregation?

When dealing with data aggregation in SQL queries in PHP, using GROUP BY is significant as it allows you to group rows that have the same values in specified columns. This is particularly useful when you want to perform aggregate functions like COUNT, SUM, AVG, etc. on the grouped data.

// Connect to the database
$connection = new mysqli("localhost", "username", "password", "database");

// Query to get the total number of orders per customer
$query = "SELECT customer_id, COUNT(order_id) AS total_orders FROM orders GROUP BY customer_id";

$result = $connection->query($query);

// Fetch and display the results
while ($row = $result->fetch_assoc()) {
    echo "Customer ID: " . $row['customer_id'] . " - Total Orders: " . $row['total_orders'] . "<br>";
}

// Close the connection
$connection->close();