What are some alternative methods to output month names in German without using if statements in PHP?

Using an array to map month numbers to their respective names in German can be a more efficient and cleaner alternative to using multiple if statements. By storing the month names in an array and accessing them based on the month number, we can avoid repetitive if conditions and make our code more manageable.

$monthNames = [
    1 => 'Januar',
    2 => 'Februar',
    3 => 'März',
    4 => 'April',
    5 => 'Mai',
    6 => 'Juni',
    7 => 'Juli',
    8 => 'August',
    9 => 'September',
    10 => 'Oktober',
    11 => 'November',
    12 => 'Dezember'
];

$monthNumber = 5; // Example month number
echo $monthNames[$monthNumber]; // Output: Mai