Skip to content

logical_operators.php

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
<html>
<head>
</head>
<body>
<?php
  $true = true;
  $false = false;
?>
<h1>Table: Testing Expressions with Logical Operators</h1>
<table border='1px solid'>
  <tr><th>Name</th><th>Example</th><th>Result</th></tr>
  <tr>
    <td>And</td>
    <td>$true && $false</td>
    <td>
      <?php 
          if ($true && $false)
          {
              echo 'Both $true and $false are true';
          }
          else
          {
              echo 'One of the values $true or $false are not true';
          }
      ?>
    </td>
  </tr>
  <tr>
    <td>|| (or)</td>
    <td>$true || $false</td>
    <td>
      <?php 
          if ($true || $false)
          {
              echo 'One of the values $true or $false are true';
          }
          else
          {
              echo 'Neither of the values $true or $false are true';
          }
      ?>
    </td>
  </tr>
  <tr>
    <td>and</td>
    <td>$true and $false</td>
    <td>
      <?php 
          if ($true and $false)
          {
              echo 'Both of the values $true and $false are true';
          }
          else
          {
              echo 'One of the values $true or $false are not true';
          }
      ?>
    </td>
  </tr>
  <tr>
    <td>Or</td>
    <td>$true or $false</td>
    <td>
      <?php 
          if ($true or $false){
            echo 'One of the values $true or $false are true';
          }else{
            echo 'Neither of the values $true or $false are true';
          }
      ?>
    </td>
  </tr>
  <tr>
    <td>Xor</td>
    <td>$true xor $false</td>
    <td>
      <?php 
          if ($true xor $false)
          {
              echo 'One of the values $true or $false are true, but not both';
          }
          else
          {
              echo 'One of the values $true or $false are not true, or both are true';
          }
      ?>
    </td>
  </tr>
<!-- ! $aNotTRUE if $a is not TRUE.  -->
  <tr>
    <td>!</td>
    <td>!$true</td>
    <td>
      <?php 
          if (!$true)
          {
              echo '$true is not true';
          }
          else
          {
              echo '$true is true';
          }
      ?>
    </td>
  </tr>
</table>
</body>
<html>