How can the use of arrays improve the readability and efficiency of code for quarterly calculations in PHP?

Using arrays can improve the readability and efficiency of code for quarterly calculations in PHP by allowing us to store quarterly data in a structured way, making it easier to access and manipulate. We can use loops to iterate over the array elements and perform calculations without repeating code. This approach can also simplify the code and make it easier to maintain in the future.

// Quarterly sales data stored in an array
$sales = [
    'Q1' => 1000,
    'Q2' => 1500,
    'Q3' => 1200,
    'Q4' => 1800
];

// Calculate total sales for the year
$totalSales = 0;
foreach ($sales as $quarter => $amount) {
    $totalSales += $amount;
}

echo "Total sales for the year: $totalSales";