Arithmetic Operators - IIOperator Name Description + Addition Adds the operands - Subtraction Subtracts the second operand from the first operand * Multiplication Multiplies operands wit
Trang 1PHP Operators
Session 5
Trang 2 An identifier is use to refer to the memory location
with the help of any variable
A data type describes the type of data a variable will
store The different data types are:
Trang 3Review - II
Numeric data or text enclosed in the quotes is considered to
be a string data type
Variable:
Name assigned to a memory location where the data is stored
Enables to retrieve data from the memory location
Dollar sign ‘$’ is placed before a variable name
Variable created without any value assigned to it then that variable takes its value as NULL
Equal to sign ‘=’ is used to assign a value to the varaible
Trang 4Review - III
Local variable:
Declared and used inside a function
Lifetime remains till the function terminates
Global variable:
Uses its value throughout the page
Declared outside the function
Called in the program with the help of the keyword global
Static variable:
Local variable made static with the help of the keyword
static
Trang 5Review - IV
Environment variable:
System-defined variable
Provides information about the transactions held
between the client and the server
Deals with the action of request and response
those are held in between the server and the client
Trang 6 Use Arithmetic operators
Use Logical operators
Use Relational operators
Use Bitwise operators
Use Assignment operators
Use String operators
Use Increment and Decrement Operators
Trang 7to perform specific actions
which the operators are evaluated in an expression
Trang 9Arithmetic Operators - II
Operator Name Description
+ Addition Adds the operands
- Subtraction Subtracts the second operand from the first
operand
* Multiplication Multiplies operands with each other
/ Division Divides the first operand by the second operand
% Modulus Returns the remainder when the first operand is
divided by the second operand
Following table lists the different arithmetic operators in PHP:
Trang 10Relational Operators - I
Operator Name Description
== Equal to Returns true if both the operands are equal
!= Not equal to Returns true if the first operand is not
equal to the second operand
< Less than Returns true if the first operand is less
than the second operand
Following table lists the different relational operators
in PHP
Trang 11Relational Operators - II
<= Less than or equal to Returns true if the first operand is
less than or equal to the second operand
> Greater than Returns true if the first operand is
greater than the second operand
>= Greater than or equal to Returns true if the first operand is
greater than or equal to the second operand
Trang 12String Operators
Concatenation Returns a concatenated string
.= Concatenating assignment Appends the argument on the right
side to the variable
String operators operate on character data
Following table lists the different string operators in PHP
Trang 13Logical Operators
or more test expression in a condition
value
Trang 14Logical Operators - I
Operator General Form Description
&& Expression1&& Expression2 Returns true only if both the
expressions are true
|| Expression1 || Expression2 Returns true if any one of
the expression is true
! !Expression Returns true only if the condition
is not true
operators:
Trang 15Logical Operators - II
Operator General Form Description
AND Expression1 AND Expression2 Returns true only if all the
expressions are true
OR Expression1 OR Expression2 Returns true if any one of the
expression is true
XOR Expression1 XOR Expression2 Returns false if both Expression1
and Expression2 are true or if both Expression1 and Expression2 are false and true otherwise
Trang 16Bitwise Operators - I
data
Trang 17Bitwise Operators - II
Operator Name General Form Description
& AND Operand1 &
Operand2 Sets to 1 if both the bits of both the operands are 1 and 0 otherwise
| OR Operand1 | Operand2 Sets to 1 if either of the bits of the
operands are 1 and 0 otherwise
Following table lists the different bitwise operators in PHP:
Trang 18Bitwise Operators - III
Operator Name General Form Description
^ EXCLUSIVE-OR Operand1 ^
Operand2 Compares two bits and sets the bit to 1 if the bits
are different and 0 otherwise
~ COMPLEMENT ~ Operand Compares and sets the bits
that are not set and 0 otherwise
Trang 19Bitwise Operators - IV
Operator Name General Form Description
<< SHIFT
LEFT Operand1 << Operand2 Shifts the bits of Operand1, Operand2
times to the left
>> SHIFT
RIGHT Operand1 >> Operand2 Shifts the bits of Operand1, Operand2
times to the right
Trang 20Assignment Operator
side to the value of the expression on the
right side
the relational operator
Trang 21Increment and Decrement
within loops such as for, do while, and while
Trang 22Increment and Decrement
Operators - II
Operand Operator Name Description
++$a Pre-increment Increments the operand value by one and
then returns this new value to the variable
$a++ Post-increment Returns the value to the variable and then
increments the operand by one
Following table lists the different increment and decrement operators in PHP:
Trang 23Increment and Decrement
Operators - III
Operand Operator Name Description
$a Pre- decrement Decrements the operand by one and then
returns this new value to the variable
$a Post decrement Returns the value to the variable and then
decrements the operand by one
Trang 25Summary - I
An Operator is any symbol that performs an
operation on an operand An operator enables us to work on variables, strings, and numbers.
Operators enable to control the program flow
The types of operators are:
Trang 26Summary - II
Arithmetic operators are used to perform
mathematical operations
Relational operators compare two operands and
determine the relationship between operands
Logical operators handle multiple conditions and
combines two or more test expression in a condition
Bitwise operators operate on the bits of an operand
Trang 27Summary - III
to a variable It enables us to set the operand on the letf side to the value on the right side.
to increase or decrease value of an operand by one
strings into a single string