From the course: PHP for WordPress
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Creating if/else statements
From the course: PHP for WordPress
Creating if/else statements
- [Instructor] Control structures are used in PHP to employ logic to our code and make things happen based on a set of criteria. All of the decision making in a program happens because of control structures. This is also where we'll use Boolean statements most often. The most common control structure is if statements. An if statement will check for a condition to be true, and if it's true, it will execute a specific set of code. Here's an example. If the variable A is greater than the variable B, then we want to echo the statement A is greater than B. Notice I'm using single quotes here, so I want the actual variable to be printed and not the value the variable is representing. This is a complete statement. There is no other code required, and what it says in plain English is if the condition A is greater than B is true, execute the following code. However, there is more code that we can add to it. First, we can add an else statement, which will execute if the condition is false. So…
Contents
-
-
-
-
(Locked)
Comparison operators and the truth4m 26s
-
(Locked)
Logical operators5m 55s
-
(Locked)
Creating if/else statements6m 53s
-
Switch and match statements4m 28s
-
(Locked)
Conditional tags in WordPress1m 19s
-
(Locked)
Loops7m 56s
-
(Locked)
The Loop in WordPress2m 54s
-
(Locked)
Challenge: Loop through an array of information1m 12s
-
(Locked)
Solution: Loop through an array of information5m 28s
-
(Locked)
-
-
-