Conditionals and Logic in PHP
Learn about the boolean data type, conditionals, `switch` statements, the ternary operator, comparison operators, and logical operators!
StartKey Concepts
Review core concepts you need to learn to master this subject
PHP else statement
PHP comparison operators
PHP If Statements
PHP switch statement
PHP readline()
PHP elseif statements
PHP Truthy and Falsy
PHP Boolean Values
PHP else statement
PHP else statement
$condition = FALSE;
if ($condition) {
// This code block will not execute
} else {
// This code block will execute
}
A PHP else statement can follow an if
block. If the condition of the if
does not evaluate to TRUE
, the code block following else
will be executed.
What you'll create
Portfolio projects that showcase your new skills
Magic 8 Ball
In this lesson, you've learned about conditionals—a fundamental yet powerful part of programming. Conditionals are so powerful, in fact, that they can be used to predict the future. In this project, you'll be creating a function that can answer any "yes" or "no" question.
PHP Number Guessing
In this project, you'll create a number guessing game. Your program will generate a random number between 1 and 10. You'll run the game 10 times and tell the user some information about their guessing abilities.
Save the Farm!
_Hello there. It's been a harrowing few weeks. First your toenail issue, and now Great-Aunt Natasha's emu farm is in danger of being reposessed! So here you are---after a brief stopover at the Mayo clinic---in Uncle Boris's remote cabin in the heart of the Terror Woods. Family legend holds that a golden statue of immense value is hidden somewhere within these walls..._ Welcome to the world of [interactive fiction](https://en.wikipedia.org/wiki/Interactive_fiction). In this project you'll be building a text adventure game called **Save the Farm**!
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory