Basic operators in php
Operators are used in PHP to perform operations using different variables and values. There are different types of operators available in PHP. They are:
1.Arithmetic operators
2.Assignment operators
3.Comparison operators
4.Increment/Decrement operators
5.Logical operators
6.String operators
7.Array operators
8.Conditional assignment operators
1.Arithmetic operators
2.Assignment operators
3.Comparison operators
4.Increment/decrement operator
5.Logical operators
6.String operators
7.Array Operators
8.Conditional operators
1.Arithmetic operators
2.Assignment operators
3.Comparison operators
4.Increment/Decrement operators
5.Logical operators
6.String operators
7.Array operators
8.Conditional assignment operators
1.Arithmetic operators
Operator | Name | Definition | Example |
---|---|---|---|
+ | Addition | To add two numbers | $x+$y |
- | Substraction | To substract two numbers | $x-$y |
* | Multiplication | To multiply two numbers | $x*$y |
/ | Division | To divide two numbers | $x/$y |
% | Modulus | To perform modulo division of two numbers | $x%$y |
** | Expontiation | To take the raising power of two numbers | $x**$y |
Operator | Name | Definition | Example |
---|---|---|---|
= | Assign | To assign right value to left variable | $x=$y |
+= | Addition | To add two numbers | $x+=$y |
-= | Substraction | To substract two numbers | $x-=$y |
*= | Multiplication | To multiply two numbers | $x*=$y |
/= | Division | To divide two numbers | $x/=$y |
%= | Modulus | To perform modulo division of two numbers | $x%=$y |
3.Comparison operators
Operator | Name | Definition | Example |
---|---|---|---|
== | is equal to | To check left value is equal to right value | $x==$y |
!= | Not equal to | To check left value is not equal to right value | $x!=$y |
> | Greater than | To check left value is greater than right value | $x>$y |
< | Less than | To check left value is less than the right value | $x<$y |
>= | Greater than or equal to | To check left value is greater than or equal to right value | $x>=$y |
<= | Less than or equal to | To check left value is less than or equal to right value | $x<=$y |
=== | Identical | To check left value is identical to right value | $x===$y |
!== | Identical | To check left value is not identical to right value | $x!==$y |
4.Increment/decrement operator
Operator | Name | Definition |
---|---|---|
++$x | Pre increment | Increment by one |
$x++ | Post increment | Increment by one |
--$x | Pre decrement | Decrement by one |
$x-- | Post decrement | Decrement by one |
Operator | Name | Definition | Example |
---|---|---|---|
and | And | Returns true if both $x and $y are true | $x and $y |
or | Or | Returns true if any of $x and $y are true | $x or $y |
xor | Xor | True if eaither $x or $y is true but not the both | $x xor $y |
&& | And | Returns true if both $x and $y are true | $x && $y |
|| | Or | Returns true if any of $x or $y is true | $x||$y |
! | Not | True if $x is false and false if $x is true | !$x |
Operator | Name | Definition | Example |
---|---|---|---|
. | Concatenation | Concatenation of $x and $y | $x.$y |
.= | Concatenation assignment | Append the value of $x with $y and stores in $x | $x.=$y |
Operator | Name | Definition | Example |
---|---|---|---|
+ | Union | Union of $x and $y | $x + $y |
== | Equality | Returns true if any of $x and $y have same value | $x==$y |
=== | Identity | Returns true if $x and $y have the same key/value pairs in the same order and of the same types | $x===$y |
!= | Inequality | Returns true if $x is not equal to $y | $x!=$y |
<> | Inequality | Returns true if $x is not equal to $y | $x<>$y |
!== | Non-identity | Returns true if $x is not identical to $y | $x!==$y |
Operator | Name | Definition | Example |
---|---|---|---|
?: | Ternary | Returns the value of $x. The value of $x is expr2 if expr1 = TRUE. The value of $x is expr3 if expr1 = FALSE | $x = expr1 ? expr2 : expr3 |
?? | Null coalescing | Returns the value of $x. The value of $x is expr1 if expr1 exists, and is not NULL. If expr1 does not exist, or is NULL, the value of $x is expr2. | $x=expr1??expr2 |
⇐Prev
Next⇒
Comments
Post a Comment