Php Operators and their Description

Php Operators and their Description
Php Operators and their Description


Php Operators to test if two values are identical

    Php Operators: A Php Language is a Special operator that is a mathematical operation performed in the Php language. Operator Can be used to solve the mathematical process and Perform logically. Operators have used variables and data calculation.


    Types of operators in Php

    1. Arithmetic Operator

    2. Relational Operator

    3. Logical Operator 

    4. Assignment operator

    5. Bitwise Operator

    6. Increment operator

    7. Decrement Operator

    8. Conditional Operator


    Php Arithmetic operators


    Arithmetic Operator: A arithmetic operation is a used mathematical operation performed.

    It is many operations performed like addition, subtraction, multiplication, and division.


    Example of Arithmetic operator


    Addition: a+b or 10+10=20

    Here a is operands value (+) Addition is operator and b is operands. It can be used for additional operations performed.

     

    Subtraction: a-b or 20-10=10

    Here a is operands value (-) Subtraction sign is operator and b is operands. It can be used as Subtraction operations performed.

     

    Multiplication: a*b or 10*10=100

    Here a is operands value (*) Multiplication sign is operator and b is operands. It can be used for Multiplication operations performed.

     

    Division: a/b or 10/5=2

    Here a is operands value (/) Division sign operator and b is operands. It can be used for Division operations performed.

     

    Modules: a%b or 10%3=1

    Here a is operands value (%) Modules sign operator and b is operands. It can be used to Modules operations performed.


    Php Arithmetic Operator Table

    Sign

    Operation

    Example

    (+)

    Addition

    (x+y)

    (-)

    Subtraction

    (x-y)

    (/)

    Multiplication

    (x*y)

    (*)

    Division

    (x/y)

    (%)

    Modules

    (x%y)


    Arithmetic Operator in Php?

    <?php 

    $x=13; 

    $y=5; 

    echo "Addition:".($x+$y)."<br>"; 

    echo "Subtraction:".($x-$y)."<br>"; 

    echo "Multiplication:".($x*$y)."<br>"; 

    echo "Division:".($x/$y)."<br>"; 

    echo "Modules:".($x%$y)."<br>";


    *****OUTPUT*****

    Addition:18 

    Subtraction:8 

    Multiplication:65 

    Division:2.6 

    Modulas:3 


    Php Comparison Operators

    Comparison Operator: Comparison operators are used in the comparison of the two operands. It can be using equal operands and condition checks in this operator. The Comparison operator is very the most useful operator.


    Php Comparision Operator Table

    Sign

    Operation

    Example

    (==)

    Equal

    (a=b)

    (!=)

    Not Equal To

    (!a=b)

    (>)

    Greater Than

    (a>b)

    (<)

    Less Than

    (a<b)

    (>=)

    Greater Than or Equal

    (a>=b)

    (<=)

    Less Than or Equal 

    (a<=b)


    Php Comparison Operator

    <?php

    $a = 80;

    $b = 50;

    $c = "80";

    var_dump($a == $c) + "\n";

    var_dump($a != $b) + "\n";

    var_dump($a <> $b) + "\n";

    var_dump($a === $c) + "\n";

    var_dump($a !== $c) + "\n";

    var_dump($a < $b) + "\n";

    var_dump($a > $b) + "\n";

    var_dump($a <= $b) + "\n";

    var_dump($a >= $b);

    ?>



    *****OUTPUT*****

    bool(true)

    bool(true)

    bool(true)

    bool(false)

    bool(true)

    bool(false)

    bool(true)

    bool(false)

    bool(true) 


    Php Logical Operators

    Logical Operators: PHP Language provides three logical operators. logical Operator tests more than one condition to make decisions. 

    Types of Logical Operator

    1.&& AND Operator

    2.|| OR Operator

    3.!  NOT Operator

    1. AND Operator can be used decisions are two values.AND Operator two values are True AND Operator return True. But two values are anyone False AND Operator return False.

    2. OR operator performs a logical condition on two expressions. if or Operator can be two expressions are True OR Operator return true. But any of the expressions are False OR Operator return True.

    3. NOT operator is elementary Operator. it can be used condition are True NOT Operator returns False and condition are False NOT Operator returns True.


     Logical Operator in php?

    <?PHP

    $marks=55; 

    if($marks>=60) 

     echo "First division<br>"; 

    if($marks<60 && $marks>=45) 

    echo "Second division<br>"; 

    if($marks<45 && $marks>=33) 

    echo "Third division<br>"; 

    if($marks<33) 

    echo "Sorry!! You are Fail!!<br>"; 

    ?>

    *****OUTPUT*****

    Second division


    Php Assignment Operator Table

    Sign

    Operation

    Example

    (=)

    a=b

    (a=b)

    (+=)

    a+=b

    (a=a+b)

    (-=)

    a-=b

    (a=a-b)

    (*=)

    a*=b

    (a=a*b)

    (/=)

    a/=b

    (a=a/b)

    (%=)

    a%=b

    (a=a%b)


    Php Bitwise Operators

    Bitwise Operator: A Bitwise operator is an operation performed on the data bit level. the bitwise operator also shifts bit right to left.

    Note: Bitwise operators are not allowed to float and double.

    Bitwise Operator Table

    Sign

    Operation

    Example

    (&)

    Bitwise AND(a&b)

    (|)

    Bitwise OR(a|b)

    (<<)

    Bitwise LEFT(a<<b)

    (>>)

    Bitwise RIGHT(a>>b)

    Bitwise Operator in php?

    <?php 

    $x=3; 

    $y=5; 

    echo "x&y:".($x&$y)."<br>"; 

    echo "x|y:".($x|$y)."<br>"; 

    echo "x>>1:".($x>>1)."<br>"; 

    echo "x<<2:".($x<<2)."<br>"; 

    echo "x^y:".($x^$y)."<br>";

     ?> 

    *****OUTPUT*****

    x&y=1 

    x|y=7 

    x>>1=1 

    x<<2=12 

    x^y=6 


    Php Increment/Decrement Operator

    Increment Operator: Increment Operators are useful operators generally used.like++x and x++ means x=x+1.

    pre-increment first adds one to the operand and then the result is assigned to the variable on the left.

    post-increment first assigns the value to the variable on the left and then increments the operand.

    Decrement Operator: A Decrement Operator has used the decrease the value. like --x and x--.

    Pre-decrement first less one to the operands and then the result is assigned to the variable on the left.

    Post-decrement first assigns the value to the variables on the left and then decrements the operands.

    increment/decrement operator

    <?PHP 

    $x=3; 

    $y=5; 

    echo "Increment ++x:".++$x."<br>"; 

    echo "Decrement --y:".--$y."<br>"; 

    ?>

    *****OUTPUT*****

    Increment ++x:4 

    Decrement --y:4 



    Php Conditional  Operator

    Conditional Operators: If the condition is true second part will execute otherwise third part will execute.

    Conditional Operator in Php

    <?php 

    $x=3; 

    $y=5; 

    $str=$x>$y?"x is greater":"y is greater"; 

    echo $str; 

    ?

    *****OUTPUT*****

    y is greater


    Read Also Other Languages Operators








    Post a Comment

    0 Comments
    * Please Don't Spam Here. All the Comments are Reviewed by Admin.