Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
If we want to check for multiple conditions at once, we can combine conditional statements using logical operators. In this video, we'll use logical operators to combine the nested if statements from the last video.
Documentation
Logical Operators allow you to combine conditional statements in the same way that you would combine phrases in a sentences. "My favorite colors are red AND purple"
XOR Operator
PHP also includes an operator called XOR, meaning "Exclusive OR". XOR checks two conditions and returns TRUE if EITHER of the conditions are true, but not both.
Let's look at an example of XOR.
if ($num == 10 XOR is_string($num)) {
echo '10 or string, but not the string "10"';
} else {
echo 'Either the string "10" or NOT 10 and NOT string';
}
Using OR evaluates to true when both expressions are true but XOR evaluates to false when both expressions are true.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up