From the course: PHP for Web Designers

Unlock the full course today

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

How PHP makes decisions

How PHP makes decisions - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

How PHP makes decisions

In this chapter, we're going to see how to change the content of web pages, depending on specific conditions. For example, you might want to show different content depending on which day or month it is. Or if a person is logged in. Or if a form has been submitted. Before doing so, we need to look at how PHP makes decisions. If you're familiar with conditional statements in JavaScript, you'll find that PHP works almost identically. Even if you're not familiar with JavaScript, you'll be glad to know that decision making is based on human language. The basic structure of a conditional statement in PHP looks like this. The keyword if is followed by a condition wrapped in parentheses. Conditions are often based on comparisons, such as whether two values are equal, or one is greater than the other. If that condition is true, all the code between the pair of curly braces will be executed. If the condition is not true, PHP skips over all the code inside the curly braces, and it carries on…

Contents