PHP Operators

PHP Operators an operator is a symbol, which helps the user to command the computer to do a certain mathmatical or logical manipulations.Operators are used in PHP Language program to operate on data and variables.
There are differant types of operator.

  • Comparison Operators.
  • Logical Operators.
  • Arithmetic Operator or Math Operators.
  • Assignment Operator.
  • Increments and Decrement Operators(Unary Operator).
  • Bit-Wise Operators.

Comparison Operators

Comparison operators are those operators. Which are used to compare values ​​of two variables. Comparison operators are used mostly in control statements. The result of Comparison variables is TRUE or FALSE. How are values ​​done with the help of Comparison operators. He can see you below.

Operator Explanation Example
Equal (==) Returns true if both operands are equal $a==$b;
Not Equal (!=) Returns true if both operands are not equal $a!=$b;
Less than (<) Returns true if first variable less than second variable $a<$b;
Greater than (>) Returns true if first variable greater than second variable $a>$b;
Less than equal to (<=) Returns true if first variable is less than or equal to second variable. $a<=$b;
Greater than equal to (>=) Returns true if first variable is greater than or equals to second variable. $a>=$b;

Logical Operator

Logical operators are used to perform logic. These operators are also used in control statements.There is no such situation in the program, in which any one of the two tasks is to be done on the basis of one condition. Then we check the Conditions using Relational Operators. But sometimes such situations are created in the program. In which one work is to be completed on the basis of more than one condition. When such a situation arises in a program, in which process with two or more conditions can be achieved. Listener, then used the Logical Operators.

Since Logical Operators are Binary Operators. Therefore, we have two Operands with these Operators, as well as the Logical Operators, who want to generate Operation Perform and Result on the basis of two Operands. They also have some Relational Operator involved. Whenever The condition on either side of the logical operator is true.Then this logical operator returns true or 1 returns. If either of the conditions on either side of the logical operator is returning 0 or False Return, then this logical operator False Returns.

Operator Explanation Example
And(&&) True if both variables are true. $a&&$b
Or(||) True if either one variable is true. $a||$b
Not(!) True if variable is not true. !$a
Xor True if only one is true not both. $a Xor $b

Arithmetic Operator or Math Operators

We are going to start with the most basic of operators–the Arithmetic operators or Math Operators.Here they are:
-> + Addition or Unary Plus.
-> Subtracts one number from another number or Unary Minus.
-> * Multiplies two numbers together.
-> / Divides one number by another.
-> % Returns the remainder when one number is divided by another (modulus).
These operators work as you’d expect: to add two values, you use the + operator like this:a+b.To subtract b from a, it’s a-b.Okay,it’s time
to get some code going.Here’s an example, arithmeticoperators.php, that puts the math operators to work:

<?php 
echo $r = '7+2';
echo $s = '7-2';
echo $t = '7*2';
echo $u = '7/2';
echo $v = '7%2';
?>
Outputs:-//
9
5
14
3.5
1

Assignment Operator

Assignment operator is used to assign a variable to a value, assigning the value of the assignment operator is very easy. [=] Is called assignment operator only. These values ​​can be assigned by 2 types.

In the first method, we assign the value directly to you, that means you create a variable. By typing assignment operator (=), you write the value forward. ($ a = 5) Assigning Direct value is quite simple.

<?php 
$a = 5;
?>

In the second way you assign a variable to another variable. By doing so, the value of the variable of the right side gets assigned to the variable of the left side. It’s called assigning by reference. You can easily understand by following the given example.

<?php 
$x = 3;
$y = $x;
Output:- $y = 3; // 3
?>

Increments and Decrement Operators(Unary Operator)

With increment and decrements operators, you can increment and decrement the value of a variable. You can increase and decrease the value. These operators (++) and (-) are. Such variables can be used in 2 ways. Which are very easy to use.
a)Post increment / decrements – In this kind of use, operators are placed behind variables. After printing this variable, it increases or decreases its value from 1 number.

$x++;

b)Pre increment / decrements – In this kind of use, operators are placed before the variable. They increase or decrease the variable before printing.

--$x;

Bit-Wise Operators

Bit wise operators perform operations on bits. Any decimal is converted into bits at the memory level. If you want to perform an operation on bits then bit wise operators can use. How to use Bit Wise Operators You can see in the example below by 1 by 1.

Operator Meaning
~ One’s Cpmplement
>> Right Shift
<< Left Shift
& Bitwise AND
| Bitwise OR
^ Bitwise XOR