# OPERATORS IN PHP

OPERATORS IN PHP

• Arithmetic Operators.
• Assignment Operators.
• Comparison Operators.
• Increment and decrement operators.
• Logical Operators.

Arithmetic operator

They are used with numeric values to perform common arithmetical operators, such as addition, subtraction, multiplication e.t.c.

Operator                    Name                          example                      result

+                            Addition                       \$x+\$y                           sum of x and y

–                             subtraction                  \$x-\$y                           difference of x and y

*                            Multiplication             \$x*\$y                           product of x and y

/                             Division                       \$x/\$y                           Quotient of x and y

%                            Modulus                      \$x%\$y                          Remainder of x and y

**                           Exponential                 \$x**\$y Result of raising \$ x to the \$y’th power

e.g

(+)

``<?php``

\$x=10;

\$y=2;

\$z=\$X+\$y

Echo \$z;

?>

// outputs:12

(_)

`` <?php ``

\$x=10;

\$y=2;

\$z=\$X-\$y

Echo \$z;

?>

` `

// outputs:8

Assignment Operators

They are used with numeric values to write a value to a variable.

The basic assignment operator in php is ”=”.It means the left operand get set to the value of the assignment expression on the right.

e.g

` `<?php``

\$x=20;

Echo \$x;

2)  (x+=y)

\$x=40;

\$y=20;

x+=y

echo \$x;

?>

//0utputs:60

PHP COMPARISON OPERATORS

The php comparison operators are used to compare two values (numbers or strings ).

e.g

` `?php ``

\$x=34;

\$x=34;

?>

ech0 (\$x==\$y);      //outputs will be true

ech0 (\$x===\$y);     //outputs will be true

ech0 (\$x!==\$y);     //outputs will be false

PHP INCREMENT/ DECREMENT OPERATORS

` `<?php``

\$x=10;

Echo ++\$x;   //output will be 11 (increment by 1)

Echo \$x;   //output will be 11 (return \$x)

?>

2) \$x++

\$x=10;

Echo \$x++ ;       //output will be 10 (return \$x)

Echo \$x;          //output will be 11 (increment by 1)

PHP LOGICAL OPERATORS

The php logical operators are used to combine conditional statements.

e.g

<?php

\$coke=100;

If((\$\$coke =100) && ((&coke>=100))) {