Lecture 16: If Statements
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
What's an Expression?
You're probably wondering what an "expression" is. Here's how PHP.net explains what an expression is:
Expressions are the most important building stones of PHP. In PHP, almost anything you write is an expression. The simplest yet most accurate way to define an expression is "anything that has a value". The most basic forms of expressions are constants and variables. When you type "$a = 5", you're assigning '5' into $a. '5', obviously, has the value 5, or in other words '5' is an expression with the value of 5 (in this case, '5' is an integer constant).
DOWNLOAD COURSE FILES HERE
http://www.bradhussey.ca/download-php...