1. Home
  2. Computing & Technology
  3. PHP / MySQL

Learn PHP - A Beginner's Guide to PHP Programing

By , About.com Guide

7 of 9

Operators

Now that you understand what an operand is we can go into more detail about what operators are. Operators tell us what to do with operands, and they fall into three major categories:

Mathematical:
+(plus), - (minus), / (divided by), and * (multiplied by)

Comparison:
> (greater than), < (less than), == (equal to), and != (not equal to)

Boolean:
&& (true if both operands are true), || (true if at least one operand is true), xor (true if ONLY one operand is true), and ! (true if a single operand is false)

Mathematical operators are exactly what they are called, they apply mathematical functions to the operands. Comparison is also pretty straight forward, they compare one operand to another operand. Boolean however may need a little more explaining.

Boolean is an extremely simple form of logic. In Boolean every statement is either True or False. Think of a light switch, it must either be turned on or off, there is no in between. Let me give you an example:

$a = true;
$b = true;
$c = false;

$a && $b;
This is asking for $a and $b to both be true, since they are both true, this expression is TRUE

$a || $b;
This is asking for $a or $b to be true. Again this is a TRUE expression

$a xor $b;
This is asking for $a or $b, but not both, to be true. Since they are both true, this expression is FALSE

! $a;
This is asking for $a to be false. Since $a is true, this expression is FALSE

! $c;
This is asking for $c to be false. Since that is the case, this expression is TRUE

Explore PHP / MySQL
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Learn PHP
  5. Learn PHP - PHP Tutorial - Operators

©2009 About.com, a part of The New York Times Company.

All rights reserved.