Part 1:if and ELSE statements1. Comparisons Operators
>Greater than
<Less than
<=Less than or equal to
>=Greater than or equal to
==Equal to
!=Not equal to
2. If statements
Now let's see how we can use the comparisons to ask yes or no questions.
Say we want to write a program this asks whether your name is longer than 7 letters. If The answer is yes, we can respond with "you have a long name!" We can do the with an if statement:
<? PHP $age =n; if $age > ) { echo "You can drive!" ; }? >
An If statement are made if up of the keyword, a condition like we ' ve seen before, and a pair of curly braces . If the answer to the condition is yes, the code inside the curly braces would run.
3. Adding an Else
<? PHP $name = "Edgar"; if ($name = = "Simon") {print "I know you!" ; } Else { print "who is?" ; }? >
Part 2:control flow:switch
1<! DOCTYPE html>234<title></title>56<body>7<?PHP8 Switch(2) {9 Case0:Ten Echo' The value is 0 '; One Break; A Case1: - Echo' The value is 1 '; - Break; the Case2: - Echo' The value is 2 '; - Break; - default: + Echo"The value isn ' t 0, 1 or 2"; - } +?> A</body> atYou have both ways of creating a switch. First, there's the made all the past exercises:
Switch ($i) {}
But we can also make it the this to:
Switch ($i):endswitch;
This is called alternative syntax. It exists to provide syntactic sugar
Conditionals and Control Flow