Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Boolean | Variables and Data Types
Introduction to PHP
course content

Contenido del Curso

Introduction to PHP

Introduction to PHP

1. First Acquaintance
2. Variables and Data Types
3. Conditional Statements
4. Arrays
5. Loops

bookBoolean

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.

php

main

copy
1234
<?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:

php

main

copy
1234
<?php $isLoggedIn = true; echo $isLoggedIn; // Outputs "1" ?>

When you use echo with false, nothing is output, as false converts to an empty string:

php

main

copy
1234
<?php $isLoggedIn = false; echo $isLoggedIn; // Does not output anything ?>

This approach allows for convenient output of boolean values without manually converting them to strings.

Choose the Correct Statements about bool in PHP

Choose the Correct Statements about bool in PHP

Selecciona unas respuestas correctas

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 4
We're sorry to hear that something went wrong. What happened?
some-alt