mohmed
Crypto Gaming Specialist
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
Introduction:
This tutorial will cover boolean variables in PHP.
What is a variable?
A variable is a piece of information which holds a value. Each variable has a type and a reference name. The value of a variable will depend on the type for that particular variable.
What types can a variable be?
There are a few different basic types of variable which include;
Strings
Booleans
Integers
Strings hold characters, letters, numbers and symbols in a string format (essentially a character array), Booleans hold a true or false value and Integers hold a full number.
When are booleans used?
Booleans are used to determine if something is true or false and as such it can only hold a 'true' or 'false' value. Booleans are used in statements such as the if and else.
Bool is the shorthand version of Boolean.
Examples:
Creating a boolean variable named 'bool':
Creating and initializing a boolean variable named 'bool':
Checking if bool is true, and if it is outputting 'Yes':
Checking if bool is true, and if it is outputting 'Yes'; the below code would NOT output:
Even though our boolean is not a string, we can still output the value. However; if it is true, it will be a string value of '1'; and a '0' if it is false:
Book traversal links for PHP Boolean Variables
This tutorial will cover boolean variables in PHP.
What is a variable?
A variable is a piece of information which holds a value. Each variable has a type and a reference name. The value of a variable will depend on the type for that particular variable.
What types can a variable be?
There are a few different basic types of variable which include;
Strings
Booleans
Integers
Strings hold characters, letters, numbers and symbols in a string format (essentially a character array), Booleans hold a true or false value and Integers hold a full number.
When are booleans used?
Booleans are used to determine if something is true or false and as such it can only hold a 'true' or 'false' value. Booleans are used in statements such as the if and else.
Bool is the shorthand version of Boolean.
Examples:
Creating a boolean variable named 'bool':
- $bool
;
Creating and initializing a boolean variable named 'bool':
- $bool
=
true
;
Checking if bool is true, and if it is outputting 'Yes':
- $bool
=
true
;
- if
(
$bool
)
{
- echo
'Yes'
;
- }
Checking if bool is true, and if it is outputting 'Yes'; the below code would NOT output:
- $bool
=
false
;
- if
(
$bool
)
{
- echo
'Yes'
;
- }
Even though our boolean is not a string, we can still output the value. However; if it is true, it will be a string value of '1'; and a '0' if it is false:
- $bool
=
true
;
- echo
$bool
;
Book traversal links for PHP Boolean Variables
- ‹ PHP Arrays
- Up
- PHP Comments ›