1
0
mirror of https://github.com/restoreddev/phpapprentice.git synced 2025-07-09 17:46:20 +02:00
Files
phpapprentice/content/06-boolean-logic.md
2019-07-13 08:48:55 -05:00

43 lines
856 B
Markdown

+++
title = "Boolean Logic"
description = "Is it a yes or a no?"
tags = ["php", "booleans"]
slug = "boolean-logic"
previous = "comparisons.html"
next = "conditionals.html"
+++
Boolean logic is used to combine booleans to return another boolean.
Using double ampersands tells PHP to check if both values are true.
If so, it will return true. If not, it will return false.
```php
<?php
$a = true;
$b = true;
$c = false;
$a && $b; // returns true
$a && $c; // returns false
```
Using two pipe characters checks if either value is true.
Then, it will return true. If both values are false, then PHP
returns false.
```php
$a = true;
$b = false;
$c = false;
$d = true;
$a || $b; // returns true
$b || $c; // returns false
$a || $d; // returns true
```
Using an exclamation point returns the opposite value.
```php
$d = true;
echo !$d; // outputs false
```