From the course: Learning PHP

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating if/else statements

Creating if/else statements - PHP Tutorial

From the course: Learning PHP

Start my 1-month free trial

Creating if/else statements

- [Instructor] Boolean statements can be used to help us decide what actions we want to take in our program. We can show a user a message based on whether they're logged in or not. We can perform a specific arithmetic operator based on a variable's value, and more. To make those decisions, we need control structures. Code that executes statements based on Boolean values. The most common of these control structures 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 a simple example. If A is greater than B, echo A is greater than B. This is a complete If statement. We start with the keyword, If, we have parentheses and inside those parentheses we have a Boolean statement, in this case, a comparison operator. Then we have an opening curly brace, the code we want to execute if that operator is true, and then the closing curly brace. It…

Contents