mirror of
https://github.com/restoreddev/phpapprentice.git
synced 2025-07-31 12:00:40 +02:00
Initial commit for public repo
This commit is contained in:
35
code/boolean-logic.php
Normal file
35
code/boolean-logic.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
// 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.
|
||||
$a = true;
|
||||
$b = true;
|
||||
$c = false;
|
||||
|
||||
// Returns true.
|
||||
$a && $b;
|
||||
// Returns false.
|
||||
$a && $c;
|
||||
|
||||
// Using two pipe characters checks if either value is true.
|
||||
// Then, it will return true. If both values are false, the PHP
|
||||
// returns false.
|
||||
$a = true;
|
||||
$b = false;
|
||||
$c = false;
|
||||
$d = true;
|
||||
|
||||
// Returns true.
|
||||
$a || $b;
|
||||
// Returns false.
|
||||
$b || $c;
|
||||
// Returns true.
|
||||
$a || $d;
|
||||
|
||||
// Using an exclamation point returns the value flipped.
|
||||
$d = true;
|
||||
|
||||
// Outputs false.
|
||||
echo !$d;
|
Reference in New Issue
Block a user