Friday, 7 June 2013

Operators in PHP

Operator- Here is an example that describes operator. Suppose, we have an expression 6+7, so 6  and 7 are called operands and + is called Operator. Here are various types of operators that are supported by PHP:-

  • Arithmetic Operators
  • Comparison Operators
  • Logical (or Relational) Operators
  • Assignment Operators
  • Conditional (or ternary) Operators

    Arithmetic Operators:-  Here are the five arithmetic operators:-
    1) + :- Adds two operands(X+Y)
    2) - :- Subtracts Second operand from first.(X-Y)
    3) * :- Multiply both Operands(X*Y)
    4) / :- Divide Numerator by Denominator(Y/X)
    5)% :- Modulus Operator and remainder of after an integer division(Y%X)
    6) ++ :- Increment operator, increases integer value by one(X++)
    7) -- :-Decrement operator, decreases integer value by one(X--)

    Comparison Operators:- Here are following Comparison Operators:-
    1) == :-Checks if the value of two operands are equal or not, if yes then condition becomes true.
    2) != :-  Checks if the value of two operands are equal or not, if values are not equal then condition becomes true.
    3) >:- Check if Left Operand is greater than right operand.
    4)  < :-Checks if Left operand is less than right operand
    5) >= :- Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.
    6) <= :- Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.

    Logical Operators: - Here are following Logical Operators:-
    1) and :- Called Logical AND operator. If both the operands are true then then condition becomes true.
    2) or:- Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true.
    3) && :-Called Logical AND operator. If both the operands are non zero then then condition becomes true.
    4) !! :-Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true.
     5) ! :-Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.

     Assignment Operators:- Here are following Assignment Operators:-
    1) =Simple assignment operator, Assigns values from right side operands to left side operand
    2) +=Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand
    3) -=Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand
    4)*=Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand
    5 /=Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand
    6)%= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand

    Conditional Operators:-This operator works on the basis of condition.  This first evaluates an expression for a true or false value and then execute one of the two given statements depending upon the result of the evaluation.Here is one conditional Operator:-
    1) ? : :- Conditional Expression

    So these are the various operators in php. Now Learn PHP online, with our blog with updated news about PHP and its related articles. 
     

No comments:

Post a Comment