PHP operators in an IF…ElseIf…Else statement. Jumping to Else?


New Member
I am trying to use the IF...ElseIf...Else statement which includes basic Logical and Comparison operators. When running the code, instead of looping trough the if statement it echos the else statement only. I followed w3schools ( and but had no luck. I am kind of confused now, is there a better way of how to do it please?
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">

    $currentHour = Date("G");

     echo $currentHour;

     if ($currentHour > "21" && $currentHour < "5")
           echo '<div class="item1" id="night">';
     elseif ($currentHour > "7" && $currentHour < "19")
           echo '<div class="item1" id="day">';
           echo '<div class="item1" id="twilight">';



Thành viên BQT
Replace && with ||.

In your if statement, if $currenthour > 21 then obviously $currenthour < 5 will fail. Similarly with your elseif statement.

Từ khóa phổ biến

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.