0% found this document useful (0 votes)
13 views

Operators: Drish Infotech LTD

Operators are symbols that are used to manipulate operands in expressions. There are different types of operators including arithmetic, assignment, comparison, increment/decrement, logical, string, and array operators. Arithmetic operators perform math operations on numeric values. Comparison operators compare two values, strings or numbers. Assignment operators assign values to variables. String operators concatenate strings.

Uploaded by

Dinesh Nandwani
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Operators: Drish Infotech LTD

Operators are symbols that are used to manipulate operands in expressions. There are different types of operators including arithmetic, assignment, comparison, increment/decrement, logical, string, and array operators. Arithmetic operators perform math operations on numeric values. Comparison operators compare two values, strings or numbers. Assignment operators assign values to variables. String operators concatenate strings.

Uploaded by

Dinesh Nandwani
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

OPERATORS

DRISH INFOTECH LTD


Contents

•INTRODUCTION TO OPERATORS
•TYPES OF OPERATORS
Introduction

• Operators are used to perform operations on


operands. These are symbols that are used in
expressions to manipulate operands.
• Operands are variables and literals contained in
an expression
Types of Operators
• Arithmetic operators
• Assignment operators
• Comparison operators
• Increment/Decrement operators
• Logical operators
• String operators
• Array operators
Arithmetic operators
Arithmetic operators are used with numeric values to perform arithmetic
operations, such as addition, subtraction, multiplication etc.
example: Arithmetic operators
Eg 1: Eg 2 :
<?php <?php
$x = 10; $x = 10;
$y = 6; $y = 6;
echo $x + $y; echo $x%$y;
?> ?>
Output: 16 Output: 4
Assignment operators

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


example: Assignment operators

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;

if ($x !== 90) {


echo "Hello world!";
}
?> output : Hello world!
String operators
• PHP has two operators that are specially designed for strings.

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!

You might also like