Posted by: Mikeplyts Jul 1 2010, 04:28 PM
Yeah, another freakin' PHP problem. However, this one seems to be really f*cking stupid. Okay, so, I have an array which contains certain time values and keys as well as an array for greetings (I know, seems like shit to waste time doing so, but I like it). In short, the following:
CODE
<?php
$time = array(
'current' => date('H'), // Current time, using the 24 hour time frame.
'late' => '24', // 12:00 AM.
'morning' => '6', // 6:00 AM.
'afternoon' => '12', // 12:00 PM.
'evening' => '19' // 7:00 PM.
);
$greeting = array(
'late' => 'Sleepy time',
'morning' => 'Good morning',
'afternoon' => 'Good afternoon',
'evening' => 'Good evening'
);
?>
And in another file:
CODE
<?php
function greeting() {
global $time, $greeting;
if ($time['current'] >= $time['late'] && $time['current'] < $time['morning']) echo $greeting['late'];
else if ($time['current'] >= $time['morning'] && $time['current'] < $time['afternoon']) echo $greeting['morning'];
else if ($time['current'] >= $time['afternoon'] && $time['current'] < $time['evening']) echo $greeting['afternoon'];
else if ($time['current'] >= $time['evening'] && $time['current'] < $time['late']) echo $greeting['evening'];
}
?>
Now, this seems to work fine. It's currently giving me the correct message (afternoon time over here). It also works for the
morning and
evening messages. However, for some reason, it goes blank when it comes to the
late message. I have a feeling it
might because of the
if and
else if statements, but I doubt it.
Any ideas regarding this issue would be appreciated.
Posted by: fixtatik Jul 2 2010, 03:28 AM
24-hour clocks go from 00:00 - 23:59.
Posted by: fixtatik Jul 2 2010, 12:55 PM
Yah.
For your times, 0 - 5.99 is late, 6 - 11.99 is morning, 12 - 19.99 is afternoon, and 20 - 23.99 is evening.