Conteúdo do Curso
Introduction to PHP
Introduction to PHP
Boolean
The boolean data type (bool
) is used to represent logical values. A boolean variable can only have two possible values: true or false. Booleans are fundamental for decision-making and conditional operations within PHP programs.
main
<?php $isActive = true; $isLogged = false; ?>
Outputting Boolean Values
You can output boolean values (true
or false
) using the echo
function. When you use echo
with true
, PHP automatically outputs "1"
, as true
converts to this string:
main
<?php $isLoggedIn = true; echo $isLoggedIn; // Outputs "1" ?>
When you use echo
with false
, nothing is output, as false
converts to an empty string:
main
<?php $isLoggedIn = false; echo $isLoggedIn; // Does not output anything ?>
This approach allows for convenient output of boolean values without manually converting them to strings.
Obrigado pelo seu feedback!