The point of coding in PHP is to make your website dynamic—or smart—so that it can make logical decisions. What I mean by this is your website can make decisions on what to do next based on user input, user conditions, or parameters you've set yourself. Here are some examples:
When a user logs into their account, they must type both their username and password. What if their password is wrong? What if they didn't type a valid email address? What if they forgot to type their email address altogether? PHP can handle what to do in these situations using If, Else, and Elseif statements.
What if a customer tries to buy a product online, but that product is sold out? PHP can let the user know the product is sold out because you can program it to calculate how many items of that product are remaining.
What if a user uploads an image that is too large? PHP can compare the uploaded image with your parameters and tell the user to upload a smaller image size if it exceeds the limit.
...and so much more!
Let's start with the If Statement. It works something like this:
If THIS then THAT
Okay, that was a little vague. Let's expand on that a bit:
If expression is TRUE, then do something
If expression is FALSE, then don't do anything
Back to If Statements
Let's see what they look like in PHP:
if (expression) {
// code to execute if expression evaluates to TRUE
}
If we expand on that further, it looks more like this:
<?php
// Set some variables
$a = 20;
$b = 50;
if ($a < $b) {
echo "Yep! $a is certainly less than $b.";
}
?>
As you can see, we are using the "less than" symbol (<) to check if the variable $a is smaller than the variable $b. If the expression is TRUE, then PHP will echo the text "Yep! 20 is certainly less than 50."
If statements can be very powerful, but these are just some very basic examples to get you started.