Ths page will show several examples of conditions in PHP

My name is Emily
My favorite game is the Sims Four. I also haven't played any of the previous Sims games.
My favorite book was written by Leslie Connor. She hasn't written a lot of books.

How Conditions Work:

Conditions in PHP work by executing some code if a condition is true. But, if a condition is not true (and the statement is more than just an if statement) then another piece of code will be executed.

If-else Condition

In my if-else condition, if the variable $name is equal to Emily, then the phrase "My name is Emily" will be the code that's executed. However, if $name wasn't equal to Emily then the phrase "My name is not Emily" would be the code that's executed.

If-elseif-else Condition

For my if-elseif-else condition, depending on what the variable $favgame equals, a different piece of code will be executed. Because I set the $favgame variable to equal Sims Four, then the code executed is, "My favorite game is the Sims Four. I also haven't played any of the previous Sims games." If $favgame was equal to a different game in the Sims franchise, then code would be executed saying that that Sims game is my favorite game. And, if $favgame was not equal to any of the Sims games, then code would be executed saying my favorite game isn't a part of the Sims franchise.

PHP switch/case

A PHP switch/case is similar to if-elseif-else conditions, but overall it's a cleaner version of if-elseif-else conditions. For my PHP switch/case, the code block will be executed where the case matches the $favbook variable Waiting for Normal by Leslie Connor. When that block of code is executed, the break statement afterwards prevents the code from running into the next case.