What are some potential approaches to reading data from an array in PHP based on a specific time condition, such as displaying a quote at 6:00 AM daily?
To display a quote at 6:00 AM daily, you can create an array of quotes and associate them with specific times. Then, you can write a PHP script that checks the current time and retrieves the quote based on the time condition.
<?php
// Array of quotes with associated times
$quotes = [
'6:00 AM' => 'Quote 1',
'9:00 AM' => 'Quote 2',
'12:00 PM' => 'Quote 3',
'3:00 PM' => 'Quote 4',
'6:00 PM' => 'Quote 5',
];
// Get the current time
$current_time = date('g:i A');
// Check if there is a quote associated with the current time
if (array_key_exists($current_time, $quotes)) {
echo $quotes[$current_time];
} else {
echo 'No quote available at this time.';
}
?>