w3reference home
PHP Tutorial


Bookmark and Share

PHP Operators

The PHP operators can be divided broadly into 5 categories namely,
  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators

Arithmetic Operators

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment
-- Decrement
Let's see a few examples.
$a = 4;
$b = 2;
$Add= $a + $b;
$Sub= $a - $b;
$Multip= $a * $b;
$Div= $a / $b;
$Mod= $a % $b;
$Increm= $a++;
$Decrem= $b--;
The reult of the above will be:
Add=6
Sub=2
Multip=8
Div=2
Mod=0
Increm=5
Decrem=1

Assignment Operators

Operator Description
= $a = $b; assigns a the value of b (Equal)
+= $a+=$b; means $a = $a+$b; (Addition)
-= $a-=$b; means $a = $a-$b; (Subtraction)
*= $a*=$b; means $a = $a*$b; (Multiplication)
/= $a/=$b; means $a = $a/$b; (Division)
.= $a.=$b; means $a = $a.$b; (Concatenation)
%= $a%=$b; means $a = $a%$b; (Modulus)
Let's take a look at a few examples:
$a = 4;
$b = 2;
1) $a = $b; (assigns a the value 4)
2) $a+=$b; (a will have the value 6)
3) $a-=$b; (a will have the value 2)
4) $a*=$b; (a will have the value 8)
5) $a/=$b; (a will have the value 2)
6) $a%=$b; (a will have the value 0)

Comparison Operators

Operator Description
== $a==$b; will return true if value of a is equal to value of b
!= $a!=$b; will return true if value of a is not equal to value of b
> $a>$b; will return true if value of a is greater than value of b
< $a<$b; will return true if value of a is less than value of b
>= $a>=$b; will return true if value of a is greater than or equal to value of b
<= $a<=$b; will return true if value of a is less than or equal to value of b
Below are a few examples:

$a == $b;// test if two values are equal
$a != $b;// test if two values are not equal
$a < $b;// test if the first value is less than the second
$a > $b;// test if the first value is greater than the second
$a <= $b;// test if the first value is less than or equal to the second
$a >= $b;// test if the first value is greater than or equal to the second

Logical Operators

Operator Description
&& and; returns true when two or more conditions are be true
|| or; returns true when either of the two conditions is true
! not; negates a given condition
Code Validator
Learn FTP
Color finder
Link Checker
Free web designs
Coming soon!
Interview Questions...
'w3reference : Learn by examples ... Advanced to beginner's tutorials ...'
Ajax: AJAX tutorial1 | Apache: Apache HTTP Server | Restarting Apache | CSS: CSS Border | CSS Syntax | CSS Selector | CSS Comment | CVS: CVS Release | CVS Login | CVS Logout | CVS Annotate | Databases: Rolap Tutorial | OLAP Tutorial | OLTP Tutorial | data warehousing | Expect: HTML: html | Linux: Dot (.) conf files | Linux Mount Point | Linux Filesystem | SSH Tutorial | Linux Commands: cal | cat | cfdisk | chroot | MySQL: MySQL Commands | PHP: PHP Basics | PHP Variables | PHP Output (echo/print) | PHP String Concat | PL/SQL: PL/SQL Data Types | PL/SQL Control Structures | PL/SQL File Extensions | PL/SQL DBMS_OUTPUT package | Python: My first Python program | Shell: Starting Bash | Bash Redirection | Bash Pipes | Bash Variables | SQL: SQL Transactions | SQL Constraints | SQL Drop | SQL Union & Union All | SVN: svn architecture | SVN Repository | SVN Import | SVN Checkout | Tech: soap | Web Designing: Web Hosting | HTML/XHTML/CSS code validator | Learn FTP | Search Engine Optimization Tips | www: XML: XML vs HTML | XML Syntax | XML Tags, Elements and Attributes | XML Namespaces |
Sitemap | Disclaim | Privacy Policy | Contact | ©2007-2009 w3reference.com All Rights Reserved.