How can PHP be used to display multiple events with different colors in a calendar layout?
To display multiple events with different colors in a calendar layout using PHP, you can create an array of events with their respective colors. Then, loop through the events and output them in the calendar layout, applying the specified colors to each event.
<?php
// Array of events with their respective colors
$events = [
['title' => 'Event 1', 'color' => 'red'],
['title' => 'Event 2', 'color' => 'blue'],
['title' => 'Event 3', 'color' => 'green']
];
// Loop through events and display them with specified colors
foreach ($events as $event) {
echo '<div style="background-color: ' . $event['color'] . ';">' . $event['title'] . '</div>';
}
?>