02.3a: Control Structures and Comparison Operators
As our programs grow and become more complex, we are going to want them to do more than print one thing over and over again. Our programs will need to make decisions. How do we do that?
<?php # * Control structures and basic comparison operators. $a = 10; $b = 5; # * Basic if statement if ($a > $b) { echo "a is greater than b\n"; } # * else statement if ($a > $b) { echo "a is greater than b\n"; } else { echo "a is NOT greater than b\n"; } # * elseif statement if ($a > $b) { echo "a is greater than b\n"; } elseif ($a == $b) { echo "a is equal to b\n"; } else { echo "a is lesser than b\n"; } # * Exercise: Modify the fahr program to print a message "It is hot" if the temp is above 26c. # * Then modify it again to also print a message "It is cold" if the temp is below 15c. ?>