Operators: Drish Infotech LTD
Operators: Drish Infotech LTD
•INTRODUCTION TO OPERATORS
•TYPES OF OPERATORS
Introduction
Eg 1: Eg 2:
<?php
$x = 50; <?php
$x -= 30; $x 10;
echo $x; $y = 6;
?> echo $x * $y;
?>
output : 20 output : 60
Comparison operators
• The PHP comparison operators are used to compare two values (number or
string)
Comparison operators
Eg 1 :
<?php
$x = 100;
$y = "100";
var_dump($x !== $y); ?>
Returns true : types are not equal
Eg 2:
<?php
$x = 50;
$y = 50;
var_dump($x <= $y); ?>
Returns true : $x is less than or equal to $y
Increment
/Decrement Operators
• The PHP increment operators are used to increment a variable's value.
• The PHP decrement operators are used to decrement a variable's value.
example : Increment
/Decrement Operators
Increment operators Decrement operators
Pre-increment operator Pre-decrement operator
<?php <?php
$x = 10; $x = 10;
echo ++$x; echo --$x;
?> ?>
Ouptut : 11
Ouput: 9
Post increment operator :
<?php Post decrement operator
$x = 10; <?php
echo $x++; $x = 10;
?> echo $x--;
Output : 10 ?>
Output: 10
example: Logical operators
• The PHP logical operators are used to combine conditional statements.
example: Logical operators
• Eg 1 :
• Eg 3:
<?php
<?php
$x = 100;
$x = 100;
$y = 50;
$y = 50;
if ($x == 100 && $y == 50) {
if ($x == 100 || $y == 80) {
echo "Hello world!";
echo "Hello world!";
}
}
?>
?>
Output : Hello world!
Output : Hello world!
• Eg 2 :
<?php
$x = 100;
1) Concatenation operator
2) concatenation assignment operators
example : String operators
• <?php
$txt1 = "Hello";
$txt2 = " world!";
echo $txt1 . $txt2;
?>
Output : Hello world!
• <?php
$txt1 = "Hello";
$txt2 = " world!";
echo $txt1 . $txt2;
?>
Output : Hello world!