NEWS & UPDATES >> BCA BCSP064 Synopsis & Project Work Started for DEC 2017, IGNOU MCA MCSP060 Synopsis Work Started for DEC 2017, CONTACT 4 IGNOU Mini Project

PHP Q/A by NiPS Ignou best Coaching Institute in Delhi

What are the Assignment operators & Other Operators in PHP

These operators are used to perform arithmetic operations to assign a value to an operand. Left operand gets set to the value of the expression on the right.
Example
Usage
Description
=
$a = 10;
Stores the value 10 in the variable $a

+=
$a += $b;
Same as
$a = $a +$b;
-=
$a -= $b;
Same as
$a = $a - $b;
*=
$a *= $b;
Same as
$a = $a * $b;
/=
$a /= $b;
Same as
$a = $a / $b;
%=
$a %= $b;
Same as
$a = $a % $b;

Unary operators

These operators are used to increment or decrement the value of an operand by1. The following table explain the usage of the increment and decrement operators.
operator
Description
Example
++
Used to increment the value of an operand by 1
$a = $b++;

--
Used to decrement the value of an operand by 1
$a = $b--;


Comparison operators

These operators are used to compare two values and execute a code block or an action on the basis of the result of that comparison. The result of the comparison operator will be ‘true’ or ‘false’
Operator
Usage
Description
Example
<
expression1 < expression2
It is used to check whether expression1 is less than expression2
$x < $y
 
True if $x is less than $y
>
expression1 > expression2
It is used to check whether expression1 is greater expression2
$x > $y
 
True if $x is greater than $y
<=
expression1 <= expression2
It is used to check whether expression1 is less than or equal to expression2
$x <= $y
 
True if $x is less than or equal to $y
>=
expression1 >= expression2
It is used to check whether expression1 is greater than or equal to expression2
$x >= $y
 
True if $x is greater than or equal to $y
==
expression1 == expression2
It is used to check whether expression1 is equal to expression2
$x == $y
 
True if $x is equal to $y
!=
expression1 != expression2
It is used to check whether expression1 is not equal to expression2
$x != $y
 
True if $x is not equal to $y
===
expression1 === expression2
It is used to check whether expression1 is identical to expression2
$x === $y
True if $x is equal to $y, and they are of the same type

Logical operators

These operators are used to evaluate expressions and return a boolean value.
Operator
Usage
Description
Example
&&
expression1 && expression2
It returns true, if both expression1 andexpression2 are true.
$x && $y
 
True if both $x and $y are true
!
! expression
It returns true, if expression is false.
!$x
 
True if $x is not true
||
expression1 || expression2
It returns true, if either expression1 orexpression2 or both of them are true.
$x || $y
 
True if either $x or $y is true

No comments:

Post a Comment