Trying to get the correct gradient colors to show based on php-time. When I try it, the gradients mismatch (I.E. topcolor from first hour-chunk and bottomcolor from fourth-hour chunk match together).

```
<?php 
$time = date("H"); 
if( $time >= 06 && $time < 12 )
$topcolor = 'black';
$bottomcolor = 'orange';
if( $time >= 12 && $time < 18 )
$topcolor = 'pink';
$bottomcolor = 'purple';
if( $time >= 18 && $time < 24 )
$topcolor = 'yellow';
$bottomcolor = 'blue';
if( $time >= 24 && $time < 6 )
$topcolor = 'red';
$bottomcolor = 'green';
?>

<style>
body {
background: <?php echo $bottomcolor;?>;
background: -webkit-linear-gradient(<?php echo $topcolor;?>, <?php echo $bottomcolor;?>) <?php echo $bottomcolor;?>;
background: -o-linear-gradient(<?php echo $topcolor;?>, <?php echo $bottomcolor;?>) <?php echo $bottomcolor;?>;
background: -moz-linear-gradient(<?php echo $topcolor;?>, <?php echo $bottomcolor;?>) <?php echo $bottomcolor;?>;
background: linear-gradient(<?php echo $topcolor;?>, <?php echo $bottomcolor;?>) <?php echo $bottomcolor;?>;
background-repeat: no-repeat;
}
</style>

```
['https://Stackoverflow.com/questions/46349085', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8303473/']
You need to wrap the statements after each `if` condition in braces:

```
if( $time >= 06 && $time < 12 )
$topcolor = 'black';
$bottomcolor = 'orange';

```

->

```
if( $time >= 06 && $time < 12 ) {
  $topcolor = 'black';
  $bottomcolor = 'orange';
}

```

If you omit these, then only the first statement will be evaluated. See <http://php.net/manual/en/control-structures.if.php>

The reason the last `$bottomcolor` is taking effect is that all of the assignments to that variable are running regardless of the `$time` value, and the last one is taking precedence.
As you can learn from the [documentation](http://php.net/manual/en/control-structures.if.php) an `if` statement looks like:

```
if (expression) 
    statement

```

And about [statements](http://php.net/manual/en/control-structures.intro.php):

> 
> A statement can be an assignment, a function call, a loop, a conditional statement or even a statement that does nothing (an empty statement). Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces. A statement-group is a statement by itself as well.
> 
> 
> 

According to the new wisdom we just got, your code is the same as this (and the indentation doesn't matter, it is there only for beauty):

```
$time = date("H"); 
if ($time >= 06 && $time < 12)
    $topcolor = 'black';
$bottomcolor = 'orange';
if ($time >= 12 && $time < 18)
    $topcolor = 'pink';
$bottomcolor = 'purple';
if ($time >= 18 && $time < 24)
    $topcolor = 'yellow';
$bottomcolor = 'blue';
if ($time >= 24 && $time < 6)           // <--- this condition is impossible
    $topcolor = 'red';
$bottomcolor = 'green';

```

As you can see, no matter the value of `$time` is, the value of `$bottomcolor` is changed to `'orange'` then to `'purple'` and so on and everytime its final value is the one produced by the last assignment (`$bottomcolor = 'green';`).

It is [recommended](http://www.php-fig.org/psr/psr-2/#control-structures) to always use blocks for the statements of [`if`](http://php.net/manual/en/control-structures.if.php), [`else`](http://php.net/manual/en/control-structures.else.php), [`elseif/else`](http://php.net/manual/en/control-structures.elseif.php), [`while`](http://php.net/manual/en/control-structures.while.php), [`do-while`](http://php.net/manual/en/control-structures.do.while.php), [`for`](http://php.net/manual/en/control-structures.for.php) and [`foreach`](http://php.net/manual/en/control-structures.foreach.php) [control structures](http://php.net/manual/en/language.control-structures.php), even when they contain only one statement. This way the code is easier to read and understand by the programmers. It doesn't make any difference for the compiler.

Back to your code, you can simplify the tests by using [`elseif`](http://php.net/manual/en/control-structures.elseif.php) statements:

```
$time = date('H');

if ($time < 6) {
    // night
    $topcolor = 'red';
    $bottomcolor = 'green';
} elseif ($time < 12) {
    // morning
    $topcolor = 'black';
    $bottomcolor = 'orange';
} elseif ($time < 18) {
    // afternoon
    $topcolor = 'pink';
    $bottomcolor = 'purple';
} else {
    // evening
    $topcolor = 'yellow';
    $bottomcolor = 'blue';
}

```