PHP Tutorial

Your cool punch line

PHP Operators

With what you have learned so far, you can assign data to variables. You can even investigate and change the data type of a variable. A programming language isn't very useful, though, unless you can manipulate the data you can store. Operators are symbols that make it possible to use one or more values to produce a new value. A value that is operated on by an operator is referred to as an operand.


1). Assignment Operators
2). Arithmetic Operators
3). Comparison Operators
4). Logical Operators

Assignment Operators

The basic assignment operator is "=". Your first inclination might be to think of this as "equal to". Don't. It really means that the the left operand gets set to the value of the expression on the rights (that is, "gets set to").


Operator Example Is The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
.= x.=y x=x.y
%= x%=y x=x%y

The value of an assignment expression is the value assigned. That is, the value of "$a = 3" is 3. This allows you to do some tricky things:

PHP Example:-

$a = ($b = 4) + 5; // $a is equal to 9 now, and $b has been set to 4.
Go Top

Arithmetic Operators

The arithmetic operators do exactly what you would expect—they perform arithmetic operations.

Remember basic arithmetic from school ? These work just like those.

Operator Example Result
Addition (+) $a + $b Sum of $a and $b.
Subtraction (-) $a - $b Difference of $a and $b.
Multiplication (*) $a * $b Product of $a and $b.
Division (/) $a / $b Quotient of $a and $b.
Modulus (%) $a % $b Remainder of $a divided by $b.


Go Top

Comparison Operators

The comparison operators perform tests on their operands. They return the Boolean value true if the test is successful, or false otherwise. This type of expression is useful in control structures, such as if and while statements.

Operators Example Result
Equal (==) $a == $b TRUE if $a is equal to $b.
Identical (===) $a === $b TRUE if $a is equal to $b, and they are of the same type. (PHP 4 only)
Not equal (!=) $a != $b TRUE if $a is not equal to $b.
Not equal (<>) $a <> $b TRUE if $a is not equal to $b.
Not identical (!==) $a !== $b TRUE if $a is not equal to $b, or they are not of the same type. (PHP 4 only)
Less than (<) $a < $b TRUE if $a is strictly less than $b.
Greater than (>) $a > $b TRUE if $a is strictly greater than $b.
Less than or equal to (<=) $a <= $b TRUE if $a is less than or equal to $b.
Greater than or equal to (>=) $a >= $b TRUE if $a is greater than or equal to $b.
Go Top

Logical Operators

The logical operators test combinations of Booleans. For example, the or operator, which is indicated by two pipe characters (||) or simply the word or, returns true if either the left or the right operand is true:
true || false

This expression returns true.

Name Example Result
And (&&) $a and $b TRUE if both $a and $b are TRUE.
Or (||) $a or $b TRUE if either $a or $b is TRUE.
Xor $a xor $b TRUE if either $a or $b is TRUE, but not both.
Not (!) ! $a TRUE if $a is not TRUE.


PHP Introduction

PHP Basic Development

PHP Control Structures

PHP Functions

PHP Arrays

PHP File System

Working With PHP Forms

PHP Classes And Objects

Introduction To Database

PHP Cookies

PHP Session

Computer SMS

More Free SMS

Review on

© . All right Sitemap Overall Visits = 2203