PHP Time Messages |
For a list of all requirements and guidelines pertaining to posting a new Help topic, please click here.
This Month's Contests | Staff Member of the Month | Hosts Looking for Hostees | Hostees looking for Hosts | BigBookofResources
Submission Guidelines
PHP Time Messages |
Jul 1 2010, 04:28 PM
Post
#1
|
|
Mel Blanc was allergic to carrots. Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 |
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. |
|
|
Jul 2 2010, 03:28 AM
Post
#2
|
|
Senior Member Group: Member Posts: 1,237 Joined: May 2008 Member No: 648,123 |
24-hour clocks go from 00:00 - 23:59.
|
|
|
Jul 2 2010, 10:34 AM
Post
#3
|
|
Mel Blanc was allergic to carrots. Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 |
So, use 0?
|
|
|
Jul 2 2010, 12:55 PM
Post
#4
|
|
Senior Member Group: Member Posts: 1,237 Joined: May 2008 Member No: 648,123 |
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. |
|
|