Jump to content

The easiest code in the world and yet it doesn't work - WTF!?


SciFiSi
Go to solution Solved by _EmilsM,

Recommended Posts

This should be the easiest thing in the world, but it just does not and WILL not work. I've spent hours and hours on this and I just do NOT understand what's wrong with this code can someone - anyone please please help and explain what I'm doing wrong!?

$hour = date('G');
echo "$hour ";

if ($hour >= 0 && $hour <= 11)
{
 echo 'Good morning ';
}
else if ($hour >=12 && $hour <=17)
{
 echo 'Good afternoon ';
}
else ($hour >=18)
{
 echo 'Good evening ';
}

All it ever prints out is Good evening! WTF!

Link to comment
Share on other sites

<?php

$hour = date('G');

echo "$hour ";

 

if ($hour >= 0 && $hour <= 11)

{

 echo 'Good morning ';

}

else if ($hour >=12 && $hour <=17)

{

 echo 'Good afternoon ';

}

else if($hour >=18 && $hour<= 24)

{

 echo 'Good evening ';

}

?>

 

using this, prints good afternoon.

 

EDIT. Maybe because $hour is now 18 to 24 for you. Define $hour for yourself, try 0, 11, 12, 17 and you'll see that it changes.

Edited by _EmilsM
Link to comment
Share on other sites

  • Solution

Only thing i did was added else if instead of else, but yea, it works perfetly for me. 

 

 


Maybe because $hour is now 18 to 24 for you. Define $hour for yourself, try 0, 11, 12, 17 and you'll see that it changes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.