Booleans
Part of the Fundamentals section of Coddy's PHP journey — lesson 8 of 71.
Boolean variables can only hold one of two possible values: true or false.
Note that these values are case-sensitive, meaning they must be lowercased.
Here is an example of assigning a bool value to a variable:
$variable_true = true;
$variable_false = false;In the above, two variables named variable_true and variable_false are initialized, with the values true and false respectively.
Booleans are the building blocks for creating logic in the programs we write. We have a whole chapter about logic and conditions.
Cheat sheet
Boolean variables hold one of two values: true or false (case-sensitive, must be lowercased).
$variable_true = true;
$variable_false = false;Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Comparison & Logical Operators
Comparison OperatorsEquality & IdentityLogical Operators Part 1Logical Operators Part 2Recap - Simple Logic2Variables and Data Types
NumbersStrings and QuotesBooleansNaming ConventionsRecap - Variable InitEmpty VariablesString ConcatenationGetting User InputCast to Different Types5Conditional Logic
If StatementIf - ElseThe Ternary OperatorNull Coalescing OperatorSwitch StatementRecap - Making Decisions3Basic Operators
Arithmetic OperatorsModulo OperatorExponentiation OperatorCombined AssignmentIncrement/DecrementOperator PrecedenceRecap - Simple CalculationsString Operators