0% found this document useful (0 votes)
328 views11 pages

PHP NOTE (Part-2)

PHP has many types of operators used to process data and values. The main types are arithmetic, string, assignment, relational, boolean, increment/decrement, and ternary operators. Arithmetic operators perform math operations like addition and subtraction. Relational operators compare two values and return true or false. Boolean operators combine expressions and return true or false. Expressions are the building blocks of PHP and contain operands and operators that evaluate to a value.

Uploaded by

kiru haran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
328 views11 pages

PHP NOTE (Part-2)

PHP has many types of operators used to process data and values. The main types are arithmetic, string, assignment, relational, boolean, increment/decrement, and ternary operators. Arithmetic operators perform math operations like addition and subtraction. Relational operators compare two values and return true or false. Boolean operators combine expressions and return true or false. Expressions are the building blocks of PHP and contain operands and operators that evaluate to a value.

Uploaded by

kiru haran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

PHp Operators

calaulate S0m
The operator aTe ted to

prDcess Compare two values

the alo ave symbo)s and


the opeands are
'

data and values

Types operators
*Axtthmetic operaton
*Strdng operaton *

Asstgnment perata
Relatlonal opexator (o) Comparison opevatan
Boolea operator lo Logical operaton.
CYemert opevaton (r) ecreman OpeTatoi "
ihuise opevatios
Temaru eperata (o) ondfttenal operatos1.

AxthmetHC operatoni

PHP was the ubuat Collectfor6 ok anithmetic


operatons

I the
Case 4 plus (t)', mnus (-and
Osterisr(*) 4 both operatoYs qre téges the
operafors is hteqin and an
produced . integen tesult is

elthex operand a double the operand


that u otre a double nesult.
OPERATOR MEANING

Addftton Adds t u memoy

Subtractfon One humben from


anothe

multtpliatfon muutfplles wo
numb togethen
Divston- Diviston one nunmber
by anothen

Madulas Return the nemfnds


.a where onel.numlben s divided by anohen.

DNiston s treated coSorme iwa excaption


that frdege dfviston done and the nesult

"tand' an rtegnal yalue, the esult produced.

. The. modulus peraton (4) ave ercepted t . the

integets.
Some Useful opeseten re dasined humeie junction
floon , nound 1and , abs min: and man.

Stsng opeTatoN

Cporadon s the concatenaton


The only 8ting
Operato. Spedted a perdod.(;) Concatenatfon operat

Eample:

42php
msg woles
hmsg "No m6a s
echo "he Message s4msa", "<br>'s
echo the hap ssag
s$Amsg "3
27
wfndows tntemet eiplorer
@htt p//localhost lcs|my-php.
The me ssaqe .is wovries
The haPPY megsag n o wories

..

NOte 4$Sthas the value apple $str {33

Assignment epe atont

PHP has some set a6signmerts Operatar


the compound assfgnment operatons are such as

Example:

C $2 + 4b) assignment operaton


a+ $b Compound assignment opexatos

RelatfonalL opeTaton

theelght nelatTonal . opevatans


C 4 , > = , <=, !=, == , = = = , ! = =) which produe
TRUE Ony both ope1ato are the Same
ony ype
and have he Same value.

! the OPpostte a =
pexator Maahing
equal t

not eual to

CreateY than

LSS than

Less than or 29uual to

oY egual to
LRSS than

I and data type


match
Equal to
Stzdngs
both t e qen CoT) both
are
equato data ype
Not
not he samne

Example:

temperature b6
4Hemperatuve >65)
:

outslde "
Tts., hlee
ech

7
Cutput:

@http /1 Jocalhdst lcs/my-php. windows Idemet


Explore
It snice outsde

Boalean eperaters CoT) Logeal operaton


-

There a v e s a b o o l e a n operators are


.

declared, they are

CReTator opeiatfonExample Resut


$a and TRUE both $a and sb +Tu.
and and

a or $b TRUE elthe $a o b tru

OR $aOr $b TRUE elthn $a xoY b tT


but hot both.

NOT TkUE sa %not True

AND TRUE s both ^a and ab is tr

OR
TRUE efthen fa or sb is tYu
The and the
and opesators peyormn
Bame
operatfbn. as do er
do
The dt4{rent between these s that the
presidence. and an ts qhex than hat
& and

hcrement and Decrément OperatoYS

Arottesi AEng you do 4nequent pHp


&ncsemenr ADD 1) o7 DeCYemert (Subtra i from)
values -

itExanMple:

a-

operato meaning x

ncremert

Decrement

Etuwise opataton

PHP also povides you a set a bitwtse


epevatou that c a waik uwäth the fndNidual
bits nstde a humbn
Cperator Meaning

Bitwtse AND

Birwise OR
A Awfse evdusive OR

Bitwise NOT
shift Jeft
Shittuqht
. .

Condfttonal eperatoY (or) ternary cperator


A ternany
epevaton pa "2" Cond?tBonal
Operatos. These actuallt i t in operato6

That acts ke e - -else statemert n


PHP
Conditon 2 epression i i epressfon 2

Exam ple :

4nesult ^a> b? da: $b


Funefons Meaning

gbs Absolute value

ConYets a numben betwean


base-Convert cases

to detmal
bindec Con vetts btnay

celt Rounds fractos up

, COstne
.: COS

desbin Converts decimal o bfney

deche ConYets,dednmal to
hexadectmal
:Convey+s dedma:+o Ctal
decot

Calcuulates eponent 4 e2
enp

Hon ROunds fracton dewn

Rekuvns the floating-point


Fmat
emalntler ot the dfviston
Convents hexadetmal to
hendec
dectmal
log lo Base to logrlthm

Rekuins the natural


Jog
Jogdthm
Find the htghest value
max

Fand the Jowest alue


octdec Convet octal to dedmal

Gets the vaue of Pi

tan tangent

Expression

Expresston are the most ampontanb buidtng


Stones PHP' In pHp, almost anyahing you wte
an expresson.

A stmplea most acurate way to detne an

epression anythêng that ha6 Value "

the
Expresston sanything that has value
Cpevanals with the opevato callea expression

Yalue are
are data OY operatoss
opeiand
Synmbol.

expneslc e oerand opevator operattoh


e presston - "operand..

Eample

sa t ¢bi

a x'k zb
10 +20
$a10
8Calan type Convenston

Expltcity type con versfon. Can be Spetyrea in


three differendt way.
The case a a ype namee in panartheses
pre coding he epessPon.

Example
value $Sum ib 4177, the follow
the
Produces 4.
Cint) Sum
ahothe way to SpectRes eplut type Comeston
s to use on the funetkon

Jnt val, double val , Stval.

Fxample
Code
$sum stiu 4.71 the followfng
neturns 4
antval C$sum)

The hrd way spey en expltcity ckype


Coesion the cet ype fun cter which taken

tuwo anameters.

*) that Spettfes a Yre


A Ynlable and a staing (
hame

Example:It $Sum Stiu 4-717 she follouwing Statemects


Comeruts the $Sum its ype ointeger
8e type yalue , chang type)
Bxampe

Settype (sum jint)

.. .

You might also like