PHP Questions
PHP Questions
ions&Answer
s–Basi
cs–2
Thi
ssetofPHPI
nter
viewQuest
ionsandAnswer
sfocuseson“
Basi
cs–2”
.
1.Whi
chi
sther
ightwayofdecl
ari
ngav
ari
abl
einPHP?
i
)$3hel
l
o
i
i
)$_
hel
l
o
i
i
i)$t
his
i
v)$Thi
s
a)Onl
yii
)
b)Onl
yii
i
)
c)i
i
),i
i
i)andi
v)
d)i
i
)andi
v)
Vi
ewAnswer
Answer
:d
Explanat
ion:
Avar
iabl
einPHPcannotst
artwi
thanumber,al
so$t
hisi
smai
nlyusedt
oref
erpr
oper
ti
esof
aclasssowecan’
tuse$thi
sasauserdefi
nevar
iabl
ename.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngcode?
<?
php
$f
oo='
Bob'
;
$bar=&$f
oo;
$bar="
Mynamei
s$bar
";
echo$bar
;
echo$f
oo;
?
>
a)Er
ror
b)Mynamei
sBobBob
c)Mynamei
sBobMynamei
sBob
d)Mynamei
sBobBob
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Fir
stl
y,t
hel
i
ne$bar=&$foo;wil
lref
erence$f
oovi
a$bar.So$bari
sassignedv
alueBob.
Ther
efor
e$bar=“Mynameis$bar
”;wi
llpr
intMynamei sBob(
$bar
=Bobassaidbefore)
.
3.Whi
choft
hef
oll
owi
ngPHPst
atement
swi
l
lout
putHel
l
oWor
ldont
hescr
een?
i
)echo(
“Hel
l
oWor
ld”
);
i
i
)pr
int(
“Hel
l
oWor
ld”
);
i
i
i)pr
int
f(“
Hel
l
oWor
ld”
);
i
v)spr
int
f(“
Hel
l
oWor
ld”
);
a)i
)andi
i
)
b)i
),i
i
)andi
i
i)
c)Al
loft
hement
ioned
d)i
),i
i
)andi
v)
Vi
ewAnswer
Answer
:b
Explanati
on:echo()
,pr
int
()andpri
ntf(
)allt
hreecanbeusedt oout
putastat
ementontot
hescr
een.The
spri
ntf()st
atementisf
uncti
onall
yidenti
calt
oprint
f()exceptt
hatt
heout
putisassi
gnedt
oastri
ngrat
her
thanrenderedtothebrowser.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or="
mar
oon"
;
$v
ar=$col
or[
2];
echo"
$var
";
?
>
a)a
b)Er
ror
c)$v
ar
d)r
Vi
ewAnswer
Answer
:d
Explanat
ion:PHPt r
eatsstri
ngsinthesamefashionasarr
ays,
all
owi
ngforspeci
ficchar
act
erst
obe
accessedv i
aarrayoffsetnot
ati
on.Inanar
ray,i
ndexalwaysst
art
sfr
om 0.Sointheli
ne$var=$col
or[
2];
if
wecountf rom star
t‘r
’comesatindex2.Sotheoutputwil
lber.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$scor
e=1234;
$scor
eboar
d=(
arr
ay)$scor
e;
echo$scor
eboar
d[0]
;
?
>
a)1
b)Er
ror
c)1234
d)2
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
The(
arr
ay)i
sacastoper
atorwhi
chi
susedf
orconv
ert
ingv
aluesf
rom ot
herdat
aty
pest
o
arr
ay.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
adv
ert
isement
<?
php
$t
otal
="25st
udent
s";
$mor
e=10;
$t
otal
=$t
otal
+$mor
e;
echo"
$tot
al"
;
?
>
a)Er
ror
b)35st
udent
s
c)35
d)25st
udent
s
Vi
ewAnswer
Answer
:c
Expl
anat
ion:Thei
ntegerval
ueatthebegi
nni
ngoftheori
ginal
$total
str
ingi
susedi
nthecal
cul
ati
on.
Howeverifi
tbegi
nswithanythi
ngbutanumeri
cal
v al
ue,
thevaluewil
lbe0.
7.Whi
choft
hebel
owst
atement
sisequi
val
entt
o$add+=$add?
a)$add=$add
b)$add=$add+$add
c)$add=$add+1
d)$add=$add+$add+1
Vi
ewAnswer
Answer
:b
Expl
anat
ion:a+=bisanaddit
ionassi
gnmentwhoseout
comei
sa=a+b.Samecanbedonewi
th
subt
ract
ion,
mult
ipl
i
cat
ion,
div
isionet
c.
8.Whi
chst
atementwi
l
lout
put$xont
hescr
een?
a)echo“
\$x
”;
b)echo“
$$x”
;
c)echo“
/$x”
;
d)echo“
$x;
”;
Vi
ewAnswer
Answer
:a
Expl
anati
on:
Abackslashi
susedsothatt
hedoll
arsi
gnist
reat
edasanor
malstr
ingchar
act
errat
herthan
promptPHPtot
reat$xasavari
abl
e.Thebacksl
ashusedi
nthi
smanneri
sknownasescapecharact
er.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngcode?
<?
php
f
unct
iont
rack(
){
st
ati
c$count=0;
$count
++;
echo$count
;
}
t
rack(
);
t
rack(
);
t
rack(
);
?
>
a)123
b)111
c)000
d)011
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Because$counti
sst
ati
c,i
tret
ainsi
tspr
evi
ousv
alueeacht
imet
hef
unct
ioni
sexecut
ed.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a="
clue"
;
$a.
="get
";
echo"
$a"
;
?
>
a)get
b)t
rue
c)f
alse
d)cl
ueget
Vi
ewAnswer
Answer
:d
Explanat
ion:
‘.
’isaconcat
enat
ionoper
ator
.$a.=“
get
”issameas$a=$a.
”get
”wher
e$ai
shav
ingv
alueof
“cl
ue”intheprevi
ousstat
ement.Sot
heoutputwi
l
lbecl
ueget
PHPQuest
ions&Answer
s–Basi
cs–3
Thi
ssetofPHPQuest
ionsandAnswer
sforFr
esher
sfocuseson“
Basi
cs–3”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=5;
$b=5;
echo(
$a===$b)
;
?
>
a)5===5
b)Er
ror
c)1
d)Fal
se
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
===oper
atorr
etur
ns1i
f$aand$bar
eequi
val
entand$aand$bhav
ethesamet
ype.
2.Whi
choft
hebel
owsy
mbol
sisanewl
i
nechar
act
er?
a)\
r
b)\
n
c)/
n
d)/
r
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
PHPt
reat
s\nasnewl
i
nechar
act
er.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$num =10;
echo'
Whati
sherage?\
nShei
s$num y
ear
sol
d'
;
?
>
a)Whati
sherage?\
nShei
s$num y
ear
sol
d
b)
Whati
sherage?
Shei
s$num y
ear
sol
d
c)Whati
sherage?Shei
s10y
ear
sol
d
d)
Whati
sherage?
Shei
s10y
ear
sol
d
Vi
ewAnswer
Answer
:a
Explanati
on:Whenastr
ingi
sencl
osedwithi
nsi
ngl
equot
esbot
hvar
iabl
esandescapesequenceswi
l
lnot
beinterpr
etedwhent
hestri
ngi
sparsed.
4.Whi
choft
hecondi
ti
onal
stat
ement
sis/
aresuppor
tedbyPHP?
i
)ifst
atement
s
i
i
)if
-el
sest
atement
s
i
i
i)i
f-
elsei
fst
atement
s
i
v)swi
tchst
atement
s
a)Onl
yi)
b)i
),i
i
)andi
v)
c)i
i
),i
i
i)andi
v)
d)i
),i
i
),i
i
i)andi
v)
Vi
ewAnswer
Answer
:d
Expl
anati
on:
Allar
econdi
ti
onalst
atementssuppor
tedbyPHPasallar
eusedtoeval
uatedif
fer
ent
condi
ti
onsduri
ngaprogr
am andtakedeci
si
onsbasedonwhethert
hesecondi
ti
onsevaluat
etotr
ueof
fal
se.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$t
eam ="
arsenal
";
swi
tch(
$team){
case"
manu"
:
echo"
Ilov
emanu"
;
case"
arsenal
":
echo"
Ilov
ear
senal
";
case"
manc"
:
echo"
Ilov
emanc"
;}
?
>
a)Il
ovear
senal
b)Er
ror
c)Il
ovear
senal
Ilov
emanc
d)Il
ovear
senal
Ilov
emancIl
ovemanu
Vi
ewAnswer
Answer
:c
Expl
anat
ion:I
fabreakst
atementi
sn’
tpr
esent
,al
lsubsequentcasebl
ockswi
l
lexecut
eunt
ilabr
eak
stat
ementisl
ocat
ed.
adv
ert
isement
6.Whi
choft
hel
oopi
ngst
atement
sis/
aresuppor
tedbyPHP?
i
)forl
oop
i
i
)whi
l
eloop
i
i
i)do-
whi
l
eloop
i
v)f
oreachl
oop
a)i
)andi
i
)
b)i
),i
i
)andi
i
i)
c)i
),i
i
),i
i
i)andi
v)
d)Onl
yiv
)
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
All
aresuppor
tedloopi
ngstat
ementsi
nPHPast
heycanr
epeatt
hesamebl
ockofcodea
gi
vennumberofti
mes,orunt
ilacer
tai
ncondi
ti
onismet
.
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$user=ar
ray
("Ashl
ey"
,"Bal
e",
"Shr
ek"
,"Bl
ank"
);
f
or(
$x=0;
$x<count
($user
);$x++) {
i
f($user
[$x]=="
Shr
ek"
)cont
inue;
pr
int
f($user
[$x]
);
}
?
>
a)Ashl
eyBal
e
b)Ashl
eyBal
eBl
ank
c)Shr
ekBl
ank
d)Shr
ek
Vi
ewAnswer
Answer
:b
Explanat
ion:Theconti
nuest
atementcausesexecut
ionoft
hecur
rentl
oopi
ter
ati
ont
oendandcommence
atthebeginningoft
henexti
terat
ion.
8.I
f$a=12whatwi
l
lber
etur
nedwhen(
$a==12)?5:
1isexecut
ed?
a)12
b)1
c)Er
ror
d)5
Vi
ewAnswer
Answer
:d
Expl
anat
ion:?:
isknownast
ernar
yoper
ator
.Ifcondi
ti
oni
str
uet
hent
hepar
tjustaf
tert
he?i
sexecut
ed
el
sethepartaf
ter:.
9.Whati
sthev
alueof$aand$baf
tert
hef
unct
ioncal
l
?
<?
php
f
unct
iondoSomet
hing(&$ar
g){
$r
etur
n=$ar
g;
$ar
g+=1;
r
etur
n$r
etur
n;
}
$a=3;
$b=doSomet
hing($a)
;
?
>
a)ai
s3andbi
s4
b)ai
s4andbi
s3
c)Bot
har
e3
d)Bot
har
e4
Vi
ewAnswer
Answer
:b
Explanati
on:
$ais4and$bis3.Thef
ormerbecause$argi
spassedbyref
erence,
thel
att
erbecauset
he
ret
urnv al
ueoft
hefunct
ioni
sacopyofthei
nit
ialv
alueoft
heargument
.
10.Whoi
sthef
atherofPHP?
a)RasmusLer
dor
f
b)Wi
l
lam Makepi
ece
c)Dr
ekKol
kev
i
d)Li
stBar
ely
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
PHPwasor
igi
nal
l
ycr
eat
edbyRasmusLer
dor
fin1994
PHPQuest
ions&Answer
s–Funct
ions
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Funct
ions”
.
1.Howt
odef
ineaf
unct
ioni
nPHP?
a)f
unct
ion{
funct
ionbody
}
b)dat
aty
pef
unct
ionName(
par
amet
ers){
funct
ionbody
}
c)f
unct
ionName(
par
amet
ers){
funct
ionbody
}
d)f
unct
ionf
unct
ionName(
par
amet
ers){
funct
ionbody
}
Vi
ewAnswer
Answer
:d
Expl
anat
ion:PHPal l
owsustocreateourownuser-
defi
nedfuncti
ons.Anynameendi
ngwithanopenand
cl
osedparenthesi
sisafunct
ion.Thekeywor
dfuncti
onisal
way susedtobegi
nafunct
ion.
2.Ty
peHi
nti
ngwasi
ntr
oducedi
nwhi
chv
ersi
onofPHP?
a)PHP4
b)PHP5
c)PHP5.
3
d)PHP6
Vi
ewAnswer
Answer
:b
Explanat
ion:PHP5i nt
roducedthef
eat
ureoftypehinti
ng.Withthehel
poft ypehi
nti
ng,
wecanspeci
fythe
expecteddataty
peofanar gumentinafuncti
ondeclar
ati
on.Fir
stvali
dtypescanbethecl
assnamesfor
argumentsthatrecei
veobject
sandtheotherarear
rayforthosethatr
eceivearr
ays.
3.Whi
cht
ypeoff
unct
ioncal
li
susedi
nli
ne8?
<?
php
f
unct
ioncal
c($pr
ice,
$tax)
{
$t
otal
=$pr
ice+$t
ax;
}
$pr
icet
ag=15;
$t
axt
ag=3;
cal
c($pr
icet
ag,
$taxt
ag)
;
?
>
a)Cal
lByVal
ue
b)Cal
lByRef
erence
c)Def
aul
tAr
gumentVal
ue
d)Ty
peHi
nti
ng
Vi
ewAnswer
Answer
:a
Explanat
ion:I
fwecallaf
uncti
onbyv al
ue,weact
uall
ypasstheval
uesofthear
gument
swhi char
estor
ed
orcopiedint
otheformalpar
ametersofthef
unct
ion.Hence,
theor
igi
nalv
aluesar
eunchangedonl
ythe
parametersi
nsidet
hefuncti
onchanges.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
f
unct
ioncal
c($pr
ice,
$tax="
")
{
$t
otal
=$pr
ice+(
$pr
ice*$t
ax)
;
echo"
$tot
al"
;
}
cal
c(42)
;
?
>
a)Er
ror
b)0
c)42
d)84
Vi
ewAnswer
Answer
:c
Expl
anat
ion:Youcandesi
gnatecer
tai
nargument
sasopt
ional
bypl
aci
ngt
hem att
heendoft
hel
i
stand
assi
gni
ngthem adefaul
tval
ueofnothi
ng.
5.Whi
choft
hef
oll
owi
ngar
eval
i
dfunct
ionnames?
i
)funct
ion(
)
i
i
)€(
)
i
i
i).
funct
ion(
)
i
v)$f
unct
ion(
)
a)Onl
yi)
b)Onl
yii
)
c)i
)andi
i
)
d)i
i
i)andi
v)
Vi
ewAnswer
Answer
:b
Expl
anati
on:Av al
i
dfunct
ionnamecanstar
twithalet
terorunder
score,
foll
owedbyanynumberoflet
ters,
numbers,orunder
scor
es.Accordi
ngt
othespecif
iedr
egularexpr
essi
on([a-
zA-
Z_\x7f
-\xf
f]
[a-
zA-
Z0-
9_\x7f
-\
xff
]*)
,afuncti
onnameli
kethisonei
svali
d.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
f
unct
iona(
)
{
f
unct
ionb(
)
{
echo'
Iam b'
;
}
echo'
Iam a'
;
}
a(
);
a(
);
?
>
a)Iam a
b)Iam bIam a
c)Er
ror
d)Iam aEr
ror
Vi
ewAnswer
Answer
:a
Explanat
ion:
Theoutputwil
lbe“
Iam a”aswear
ecal
l
inga(
);sot
hest
atementout
sidet
hebl
ockof
functi
onb()wil
lbecal
led.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
f
unct
iona(
)
{
f
unct
ionb(
)
{
echo'
Iam b'
;
}
echo'
Iam a'
;
}
b(
);
a(
);
?
>
a)Iam b
b)Iam bIam a
c)Er
ror
d)Iam aEr
ror
Vi
ewAnswer
Answer
:c
Expl
anat
ion:TheoutputwillbeFat
aler
ror
:Call
toundefi
nedfunct
ionb(
).Youcannotcal
laf
unct
ionwhi
ch
i
sinsi
deaf unct
ionwithoutcall
i
ngtheout
sidefunct
ionf
ir
st.I
tshoul
dbea();
thenb();
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$op2="
blabl
a";
f
unct
ionf
oo(
$op1)
{
echo$op1;
echo$op2;
}
f
oo(
"hel
l
o")
;
?
>
a)hel
l
obl
abl
a
b)Er
ror
c)hel
l
o
d)hel
l
obl
abl
abl
abl
a
Vi
ewAnswer
Answer
:c
Explanati
on:Ifuwantt
oputsomev ar
iabl
esi
nfunct
iont
hatwasnotpassedbyi
t,y
oumustuse“
global
”.
I
nsidet hefunct
iont
ypegl
obal$op2.
9.Af
unct
ioni
nPHPwhi
chst
art
swi
th_
_(doubl
eunder
scor
e)i
sknowas.
.
a)Magi
cFunct
ion
b)I
nbui
l
tFunct
ion
c)Def
aul
tFunct
ion
d)UserDef
inedFunct
ion
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
PHPf uncti
onsthatst
artwit
hadoubleunder
score–a“__
”–arecal
ledmagi
cfuncti
onsi
n
PHP.Theyaref
unctionsthatar
ealwaysdef
inedi
nsi
declasses,
andar
enotst
and-al
onef
uncti
ons.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
f
unct
ionf
oo(
$msg)
{
echo"
$msg"
;
}
$v
ar1="
foo"
;
$v
ar1(
"wi
l
lthi
swor
k")
;
?
>
a)Er
ror
b)$msg
c)0
d)Wi
l
lthi
swor
k
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Iti
spossi
blet
ocal
laf
unct
ionusi
ngav
ari
abl
ewhi
chst
orest
hef
unct
ionname.
PHPQuest
ions&Answer
s–I
n-Bui
l
tFunct
ionsi
nPHP
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
In-
Bui
l
tFunct
ionsi
nPHP”
.
1.Whi
choft
hef
oll
owi
ngPHPf
unct
ionsaccept
sanynumberofpar
amet
ers?
a)f
unc_
get
_ar
gv(
)
b)f
unc_
get
_ar
gs(
)
c)get
_ar
gv(
)
d)get
_ar
gc(
)
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
func_
get_ar
gs()r
etur
nsanarrayofargument
sprovi
ded.Onecanusef
unc_
get
_ar
gs(
)insi
de
thef
unct
iontoparseanynumberofpassedparameter
s.Her
eisanexample:
f
unct
ionf
oo(
)
{
$ar
gs=f
unc_
get
_ar
gs(
);
f
oreach(
$ar
gsas$k=>$v
)
{
echo"
arg"
.(
$k+1)
."
:$v
\n"
;
}
}
f
oo(
);
/
*wi
l
lpr
intnot
hing*
/
f
oo(
"Hel
l
o")
;
/
*wi
l
lpr
intHel
l
o*/
f
oo(
"Hel
l
o",
"Wor
ld"
,"
Bye"
);
/
*wi
l
lpr
intHel
l
oWor
ldBy
e*/
2.Whi
choneoft
hef
oll
owi
ngPHPf
unct
ionscanbeusedt
ofi
ndf
il
es?
a)gl
ob(
)
b)f
il
e()
c)f
old(
)
d)get
_fi
l
e()
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Thef
unct
iongl
ob(
)ret
urnsanar
rayoff
il
enamesordi
rect
ori
eswhi
chmat
chesaspeci
fi
ed
patt
ern.Thef
unct
ionr
etur
nsanar
rayoff
il
es/
dir
ect
ori
es,
ori
twi
l
lret
urnFALSEonf
ail
ure.Her
eisan
example-
/
/getal
lphpf
il
esANDt
xtf
il
es
$f
il
es=gl
ob(
'*
.{php,
txt
}'
,GLOB_
BRACE)
;
pr
int
_r(
$fi
l
es)
;
/
*out
putl
ooksl
i
ke:
Ar
ray
(
[
0]=>phpt
est
.php
[
1]=>pi
.php
[
2]=>post
_out
put
.php
.
.
.
)
3.Whi
choft
hef
oll
owi
ngPHPf
unct
ionscanbeusedt
ogett
hecur
rentmemor
yusage?
a)get
_usage(
)
b)get
_peak_
usage(
)
c)memor
y_get
_usage(
)
d)memor
y_get
_peak_
usage(
)
Vi
ewAnswer
Answer
:c
Explanati
on:memory_get
_usage(
)retur
nstheamountofmemor y,inbyt
es,t
hat’
scurrent
lybeing
al
locatedtothePHPscr i
pt.Wecansettheparameter‘r
eal
_usage’toTRUEt ogett
otalmemor yall
ocated
fr
om sy st
em, i
ncl
udi
ngunusedpages.Ifiti
snotsetorFALSEt henonlytheusedmemor yisreport
ed.To
getthehighestamountofmemor yusedatanypoint,
wecanuset hememor y_
get_
peak_usage()funct
ion.
4.Whi
choft
hef
oll
owi
ngPHPf
unct
ionscanbeusedf
orgener
ati
nguni
quei
ds?
a)uni
quei
d()
b)i
d()
c)md5(
)
d)mdi
d()
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Thef
unct
ionuni
quei
d()i
susedt
ogener
ateauni
queI
Dbasedont
hemi
crot
ime(
cur
rentt
ime
i
nmi cr
oseconds)
.TheIDgener
atedf
rom thefuncti
onuniquei
d()i
snotopt
imal
,asiti
sbasedonthe
sy
stem ti
me.Togenerat
eanIDwhichisextr
emel ydi
ff
icul
ttopredi
ctwecanusethemd5()f
unct
ion.
5.Whi
choneoft
hef
oll
owi
ngf
unct
ionscanbeusedt
ocompr
essast
ri
ng?
a)zi
p_compr
ess(
)
b)zi
p()
c)compr
ess(
)
d)gzcompr
ess(
)
Vi
ewAnswer
Answer
:d
Expl
anat
ion:Thef
uncti
ongzcompress(
)compressest
hestri
ngusi
ngtheZLIBdat
afor
mat.Onecan
achi
eveupto50%sizer
educti
onusingt
hisf
uncti
on.Thegzuncompr
ess(
)funct
ioni
susedtouncompr
ess
thest
ri
ng.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echochr
(52)
;
?
>
a)1
b)2
c)3
d)4
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Thechr()funct
ionreturnsacharact
erfrom t
hespeci
fi
edASCIIv al
ue.Wecanspeci
fyASCII
val
ueindeci
mal,oct
al,
orhexv alues.TheOctalval
uesaredef
inedasaleading0,whi
lehexval
uesare
defi
nedasaleadi
ng0x.SincetheASCI Ival
ueof4is52, t
hus4wasdisplay
ed.
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echoor
d("
hi"
);
?
>
a)106
b)103
c)104
d)209
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Theord(
)funct
ionret
urnst
heASCI
Ival
ueoft
hef
ir
stchar
act
erofast
ri
ng.TheASCI
Ival
ueof
his104,
thus104wasdispl
ayed.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$st
r="
Hel
l
oWor
ld"
;
echowor
dwr
ap(
$st
r,
5,
"<br
>\n"
);
?
>
a)Hel
l
oWor
ld
b)
Hel
l
o
Wor
ld
c)
Hel
l
owo
r
ld
adv
ert
isement
d)Wor
ld
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thewor
dwr
ap(
)funct
ionwr
apsast
ri
ngi
ntonewl
i
neswheni
treachesaspeci
fi
clengt
h.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echoucwor
ds(
"il
ovemycount
ry"
);
?
>
a)Il
ovemycount
ry
b)i
lov
emyCount
ry
c)Il
ovemyCount
ry
d)ILov
eMyCount
ry
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Theucwor
ds(
)funct
ionconv
ert
sthef
ir
stchar
act
erofeachwor
dinast
ri
ngt
oupper
case.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echol
cfi
rst
("
wel
comet
oIndi
a")
;
?
>
a)wel
comet
oIndi
a
b)wel
comet
oindi
a
c)Wel
comet
oIndi
a
d)Wel
comet
oindi
a
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Thel
cfi
rst
()f
unct
ionconv
ert
sthef
ir
stchar
act
erofast
ri
ngt
olower
case.
PHPQuest
ions&Answer
s–Ar
ray
s-1
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Arr
ays”
.
1.PHP’
snumer
ical
l
yindexedar
raybegi
nwi
thposi
ti
on_
___
___
___
_
a)1
b)2
c)0
d)-
1
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Likeal
ltheot
herpr
ogr
ammi
ngl
anguages,
thef
ir
stel
ementofanar
rayal
way
sst
art
swi
th‘
0’
.
2.Whi
choft
hef
oll
owi
ngar
ecor
rectway
sofcr
eat
inganar
ray
?
i
)st
ate[
0]=“
kar
nat
aka”
;
i
i
)$st
ate[
]=ar
ray
(“kar
nat
aka”
);
i
i
i)$st
ate[
0]=“
kar
nat
aka”
;
i
v)$st
ate=ar
ray
(“kar
nat
aka”
);
a)i
i
i)andi
v)
b)i
i
)andi
i
i)
c)Onl
yi)
d)i
i
),i
i
i)andi
v)
Vi
ewAnswer
Answer
:a
Expl
anati
on:
Av ari
abl
enameshoul
dst
artwi
th$symbolwhichi
snotpr
esenti
ni)andy
ouneednotput
thesquar
ebracket
swhenyouuset
hearr
ay(
)const
ruct
or.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngphpcode?
<?
php
$st
ates=ar
ray
("Kar
nat
aka"=>ar
ray
(
"popul
ati
on"=>"
11,
35,
000"
,"capi
tal
"=>"
Bangal
ore"
),
"
Tami
lNadu"=>ar
ray
("popul
ati
on"=>"
17,
90,
000"
,
"
capi
tal
"=>"
Chennai
"))
;
echo$st
ates[
"Kar
nat
aka"
][
"popul
ati
on"
];
?
>
a)Kar
nat
aka11,
35,
000
b)11,
35,
000
c)popul
ati
on11,
35,
000
d)Kar
nat
akapopul
ati
on
Vi
ewAnswer
Answer
:b
Explanati
on:I
nthefol
lowi
ngPHPcode,t
hevar
iabl
estat
esaretr
eatedasamul
ti
dimensi
onal
arr
ayand
accordingl
ytr
aver
seittogett
hev
alueof‘
Kar
nataka’
spopul
ati
on’
.
4.Whi
choft
hef
oll
owi
ngPHPf
unct
ionwi
l
lret
urnt
ruei
fav
ari
abl
eisanar
rayorf
alsei
fiti
snotanar
ray
?
a)t
his_
arr
ay(
)
b)i
s_ar
ray
()
c)do_
arr
ay(
)
d)i
n_ar
ray
()
Vi
ewAnswer
Answer
:b
Expl
anati
on:
Thefunct
ionis_ar
ray
()isaninbuil
tfunct
ioninPHPwhi
chisusedt
ocheckwhet
herav
ari
abl
e
i
sanar r
ayornot
.It
sprototy
pefoll
ows:booleanis_ar
ray(
mixedv
ari
abl
e).
5.Whi
chi
n-bui
l
tfunct
ionwi
l
laddav
aluet
otheendofanar
ray
?
a)ar
ray
_unshi
ft
()
b)i
nto_
arr
ay(
)
c)i
nend_
arr
ay(
)
d)ar
ray
_push(
)
Vi
ewAnswer
Answer
:d
Expl
anat
ion:ar
ray
_pushaddsav al
uetotheendofanar
ray
,ret
urni
ngt
het
otal
countofel
ement
sint
he
arr
ayaft
erthenewvaluehasbeenadded.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$st
ate=ar
ray(
"Kar
nat
aka"
,"Goa"
,"Tami
lNadu"
,
"
Andhr
aPr
adesh"
);
echo(
arr
ay_
sear
ch(
"Tami
lNadu"
,$st
ate))
;
?
>
a)Tr
ue
b)1
c)Fal
se
d)2
Vi
ewAnswer
Answer
:d
Expl
anati
on:
Thearr
ay_search(
)funct
ionsear
chesanar
rayf
oraspeci
fi
edv
alue,
ret
urni
ngi
tskeyi
f
l
ocatedandFALSEot
herwise.
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$f
rui
ts=ar
ray(
"appl
e",
"or
ange"
,"banana"
);
echo(
next
($f
rui
ts)
);
echo(
next
($f
rui
ts)
);
?
>
a)or
angebanana
b)appl
eor
ange
c)or
angeor
ange
d)appl
eappl
e
Vi
ewAnswer
Answer
:a
Expl
anat
ion:Thenext
()f
uncti
onr
etur
nst
heval
ueofthenextel
ementi
nthear
ray
.Int
hef
ir
st‘
next
($f
rui
ts)
’
cal
l,
itwi
llpr
intor
angewhichi
snextt
oappl
eandsoon.
adv
ert
isement
8.Whi
choft
hef
oll
owi
ngf
unct
ioni
susedt
ogett
hev
alueoft
hepr
evi
ousel
ementi
nanar
ray
?
a)l
ast
()
b)bef
ore(
)
c)pr
ev(
)
d)pr
evi
ous(
)
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Thepr
ev(
)funct
ionr
etur
nst
hepr
evi
ousel
ementi
nthear
ray
.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$f
rui
ts=ar
ray(
"appl
e",
"or
ange"
,ar
ray(
"pear
","
mango"
),
"
banana"
);
echo(
count
($f
rui
ts,
1))
;
?
>
a)3
b)4
c)5
d)6
Vi
ewAnswer
Answer
:d
Expl
anati
on:Thefuncti
oncount()wi
ll
retur
nthenumberofelementsi
nanarray.Thepar
amet
er1count
s
thear
rayrecur
siv
elyi.
eitwi
llcountal
ltheel
ementsofmult
idimensi
onal
arr
ay s.
10.Whi
chf
unct
ionr
etur
nsanar
rayconsi
sti
ngofassoci
ati
vekey
/val
uepai
rs?
a)count
()
b)ar
ray
_count
()
c)ar
ray
_count
_val
ues(
)
d)count
_val
ues(
)
Vi
ewAnswer
Answer
:c
Explanati
on:Thefunct
ionarr
ay_count
_val
ues(
)wil
lcountal
ltheval
uesofanarray
.Itwil
lret
urnan
associati
vearray
,wherethekey
swi l
lbetheor
igi
nalar
ray’
svalues,
andtheval
uesarethenumberof
occurrences.
PHPCodi
ngQuest
ionsandAnswer
s–Ar
ray
s–2
Thi
ssetofTr
ickyPHPQuest
ions&Answer
sfocuseson“
Arr
ays–2”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$car
s=ar
ray
("Vol
vo"
,"BMW"
,"Toy
ota"
);
echo"
Ili
ke".$car
s[2]."
,".$car
s[1]."and".$car
s[0]."
."
;
?
>
a)Il
i
keVol
vo,
Toy
otaandBMW
b)Il
i
keVol
vo,
BMW andToy
ota
c)Il
i
keBMW,
Vol
voandToy
ota
d)Il
i
keToy
ota,
BMW andVol
vo
Vi
ewAnswer
Answer
:d
Expl
anati
on:Theor
derofelementsdefi
ned.I
ntheechostat
ementwhenwecallt
heel
ement
sofarr
ay
usi
ngitsi
ndex,i
twi
llbepr
intedaccordi
ngl
y.Asindex‘
0’i
ndi
cat
es‘Vol
vo’
,‘1’
for‘
BMW’and‘
2’f
orToyot
a’.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$f
name=ar
ray
("Pet
er"
,"Ben"
,"Joe"
);
$age=ar
ray
("35"
,"37"
,"43"
);
$c=ar
ray
_combi
ne(
$age,
$fname)
;
pr
int
_r(
$c)
;
?
>
a)Ar
ray(Pet
erBenJoe)
b)Ar
ray([
Pet
er]=>35[
Ben]=>37[
Joe]=>43)
c)Ar
ray(353743)
d)Ar
ray([
35]=>Pet
er[
37]=>Ben[
43]=>Joe)
Vi
ewAnswer
Answer
:d
Explanati
on:Here“keys”ar
rayis$ageand“val
ues”arrayi
s$fname.Thefunct
ionarr
ay_
combi
ne(
)wil
l
createanarraybyusingtheelementsf
rom one“keys”arr
ayandone“val
ues”arr
ay.Sowhenv
ari
abl
ecis
call
ed,itwil
lpri
ntkeysandv al
ues.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=ar
ray
("A"
,"
Cat
",
"Dog"
,"
A",
"Dog"
);
$b=ar
ray
("A"
,"
A",
"Cat
",
"A"
,"
Tiger
");
$c=ar
ray
_combi
ne(
$a,
$b)
;
pr
int
_r(
arr
ay_
count
_val
ues(
$c)
);
?
>
a)Ar
ray([
A]=>5[
Cat
]=>2[
Dog]=>2[
Tiger
]=>1)
b)Ar
ray([
A]=>2[
Cat
]=>2[
Dog]=>1[
Tiger
]=>1)
c)Ar
ray([
A]=>6[
Cat
]=>1[
Dog]=>2[
Tiger
]=>1)
d)Ar
ray([
A]=>2[
Tiger
]=>1)
Vi
ewAnswer
Answer
:d
Expl
anati
on:
Thefunct
ionThear
ray
_count
_val
ues(
)count
sallt
heval
uesofanarr
ayandtheThefuncti
on
arr
ay_combi
ne(
)wil
lcr
eateanar
raybyusi
ngtheel
ementsfr
om one“key
s”ar
rayandone“val
ues”ar
ray.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a1=ar
ray
("a"=>"
red"
,"b"=>"
green"
,"c"=>"
blue"
,"d"=>"
yel
l
ow"
);
$a2=ar
ray
("e"=>"
red"
,"f
"=>"
green"
,"g"=>"
blue"
,"h"=>"
orange"
);
$a3=ar
ray
("i
"=>"
orange"
);
$a4=ar
ray
_mer
ge(
$a2,
$a3)
;
$r
esul
t=ar
ray
_di
ff
($a1,
$a4)
;
pr
int
_r(
$resul
t)
;
?
>
a)Ar
ray([
d]=>y
ell
ow)
b)Ar
ray([
i]=>or
ange)
c)Ar
ray([
h]=>or
ange)
d)Ar
ray([
d]=>y
ell
ow[
h]=>or
ange)
Vi
ewAnswer
Answer
:a
Explanati
on:Thearray
_dif
f()f
uncti
oncompar estheval
uesoftwo(ormore)arr
ays,
andret
urnsthe
dif
ferences.Thi
sfuncti
oncompar est
hevaluesoftwo( ormore)ar
ray
s,andret
urnanar
raythatcont
ains
theentri
esf r
om ar
ray1thatarenotpr
esentinotherarr
ays(ar
ray2,
arr
ay3,et
c).
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a1=ar
ray
("r
ed"
,"gr
een"
);
$a2=ar
ray
("bl
ue"
,"y
ell
ow"
);
$a3=ar
ray
_mer
ge(
$a1,
$a2)
;
$a4=ar
ray
("a"
,"b"
,"c"
,"d"
);
$a=ar
ray
_combi
ne(
$a4,
$a3)
;
pr
int
_r(
$a)
;
?
>
a)Ar
ray([
a]=>bl
ue[
b]=>y
ell
ow[
c]=>r
ed[
d]=>gr
een)
b)Ar
ray([
0]=>bl
ue[
1]=>y
ell
ow[
2]=>r
ed[
3]=>gr
een)
c)Ar
ray([
0]=>r
ed[
1]=>gr
een[
2]=>bl
ue[
3]=>y
ell
ow)
d)Ar
ray([
a]=>r
ed[
b]=>gr
een[
c]=>bl
ue[
d]=>y
ell
ow)
Vi
ewAnswer
Answer
:d
Explanati
on:Thefuncti
onarray_mer ge()mergesoneormor earray
sintoonearray.Ifi
nthefuncti
on
array_merge()
,twoormor earrayelement shavethesamekey,thelastoneover
ridestheothers.The
functionarr
ay_combine(
)willcreat
eanar r
aybyusingtheel
ement sfrom one“
key s”ar
rayandone“ val
ues”
array.Theprogram i
sthebasiccombi nedappli
cati
onofarr
ay_combine()andarray_merge(
).
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=ar
ray
("a"=>"
indi
a",
"b"=>"
brazi
l
","
c"=>"
chi
na"
);
echoar
ray
_shi
ft
($a)
;
echo"
<br
>";
ar
ray
_pop(
$a)
;
pr
int
_r(
$a)
;
?
>
a)
i
ndi
a
Ar
ray([
b]=>Br
azi
l)
adv
ert
isement
b)
i
ndi
a
Ar
ray([
a]=>br
azi
l)
c)
chi
na
Ar
ray([
a]=>i
ndi
a)
d)
chi
na
Ar
ray([
a]=>br
azi
l)
Vi
ewAnswer
Answer
:a
Explanat
ion:Thefuncti
onarr
ay_shif
t()r
emov esthefi
rstelementfrom anar
ray
,anditr
etur
nstheval
ueof
theremov edelementandthefuncti
onarray_pop(
)delet
est helastel
ementofanarr
ay.So“a”=>“
Indi
a”,
“c”=>“China”wil
lbedelet
edand“ b”=>“Brazil
”wil
lbeprinted.
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a1=ar
ray
_fi
l
l(1,
4,"
hel
l
o")
;
$b1=ar
ray
_fi
l
l(5,
1,"
php"
);
$a2=ar
ray
_mer
ge(
$a1,
$a2)
;
pr
int
_r(
$a2)
;
echo"
<br
>";
pr
int
_r(
$b1)
;
?
>
a)
Ar
ray([
1]=>hel
l
o[4]=>hel
l
o[5]=>php)
Ar
ray([
5]=>php)
b)
Ar
ray([
1]=>hel
l
o[2]=>hel
l
o[3]=>hel
l
o[4]=>hel
l
o)
Ar
ray([
5]=>php)
c)
Ar
ray([
1]=>hel
l
o[2]=>hel
l
o[3]=>hel
l
o[4]=>hel
l
o[5]=>php)
Ar
ray([
5]=>php)
d)
Ar
ray([
1]=>hel
l
o[2]=>hel
l
o[3]=>hel
l
o[4]=>hel
l
o)
Ar
ray([
1]=>php)
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Usageofar
ray
_fi
l
l()andar
ray
_mer
ge(
)funct
ions.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$names=ar
ray
("Sam"
,"Bob"
,"Jack"
);
echo$names[
0]."
ist
hebr
otherof".$names[
1]."and".$names[
1]."
."
;
?
>
a)Sam i
sthebr
otherofBobandJack
b)Sami
sthebr
otherofBobandBob
c)Sam i
sthebr
otherofJackandBob
d)Er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:Si
mpledef
ini
ti
onofar
rayandusi
ngi
tinast
ri
ng.Wehav
eused$names[
1]t
wiceandhence
Bobappearstwi
ce.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$names=ar
ray
("Sam"
,"Bob"
,"Jack"
);
echo$names[
0].
"i
sthebr
otherof"
.$names[
1].
"and"
.$names[
1].
".
".
$br
other
;
?
>
a)Sam i
sthebr
otherofBobandBob)$br
other
b)Sam i
sthebr
otherofBobandBob)
c)$br
other
d)Er
ror
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
$br
otherundecl
ared.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$pl
ace=ar
ray
("NYC"
,"LA"
,"Par
is"
);
ar
ray
_pop(
$pl
ace)
;
$pl
ace1=ar
ray
("Par
is"
);
$pl
ace=ar
ray
_mer
ge(
$pl
ace,
$pl
ace1)
;
pr
int
_r(
$pl
ace)
;
?
>
a)Ar
ray([
0]=>LA[
1]=>Par
is[
2]=>Par
is)
b)Ar
ray([
0]=>NYC[
1]=>LA[
2]=>Par
is)
c)Ar
ray([
0]=>NYC[
1]=>LA[
2]=>Par
is[
3]=>Par
is)
d)Ar
ray([
0]=>LA[
1]=>Par
is)
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
arr
ay_
mer
ge(
)andar
ray
_pop(
)yi
eldst
hatr
esul
t.
PHPCodi
ngQuest
ionsandAnswer
s–Ar
ray
s–3
Thi
ssetofToughPHPQuest
ions&Answer
sfocuseson“
Arr
ays–3”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$age=ar
ray
("Har
ry"=>"
21"
,"Ron"=>"
23"
,"
Mal
foy
"=>"
21"
);
ar
ray
_pop(
$age)
;
pr
int
_r(
arr
ay_
change_
key
_case(
$age,
CASE_
UPPER)
);
?
>
a)Ar
ray([
Har
ry]=>21[
Ron]=>23[
Mal
foy
]=>21)
b)Ar
ray([
HARRY]=>21[
RON]=>23[
MALFOY]=>21)
c)Ar
ray([
HARRY]=>21[
RON]=>23)
d)Ar
ray([
Har
ry]=>21[
Ron]=>23)
Vi
ewAnswer
Answer
:c
Expl
anation:Thefuncti
onarr
ay_pop()wil
ldel
etet
hel
astel
ementofanarr
ay.SoMalf
oy=>21wil
lbe
del
etedandt hefuncti
onarr
ay_change_key_
case(
)wi
l
lchangeal
lkeysi
nanarrayt
olower
caseor
uppercase.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a1=ar
ray
("a"=>"
red"
,"b"=>"
green"
,"c"=>"
blue"
,"d"=>"
yel
l
ow"
);
$r
esul
t=ar
ray
_fl
i
p($a1)
;
pr
int
_r(
$resul
t)
;
?
>
a)Ar
ray([
red]=>r
ed[
green]=>gr
een[
blue]=>bl
ue[
yel
l
ow]=>y
ell
ow)
b)Ar
ray([
a]=>a[
b]=>b[
c]=>c[
d]=>d)
c)Ar
ray([
red]=>a[
green]=>b[
blue]=>c[
yel
l
ow]=>d)
d)Ar
ray([
a]=>r
ed[
b]=>gr
een[
c]=>bl
ue[
d]=>y
ell
ow)
Vi
ewAnswer
Answer
:c
Explanat
ion:
Thefunct
ionar
ray
_fl
i
p( )f
li
ps/
exchangesal
lkeyswit
hthei
rassoci
atedval
uesi
nanar
ray
.So,
i
nt heaboveprogr
am “
a”wil
lbefl
ippedwit
h“red”,
“b”wi
llbefl
i
ppedwit
h“green”andsoon.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a1=ar
ray
("a"=>"
red"
,"b"=>"
green"
,"c"=>"
blue"
,"d"=>"
yel
l
ow"
);
$a2=ar
ray
("e"=>"
red"
,"
f"=>"
green"
,"g"=>"
blue"
);
$r
esul
t=ar
ray
_int
ersect
($a1,
$a2)
;
pr
int
_r(
$resul
t)
;
?
>
a)Ar
ray([
a]=>r
ed[
b]=>gr
een[
c]=>bl
ue)
b)Ar
ray([
a]=>r
ed[
b]=>gr
een[
c]=>bl
ue[
d]=>y
ell
ow)
c)Ar
ray([
e]=>r
ed[
f]=>gr
een[
g]=>bl
ue)
d)Ar
ray([
a]=>r
ed[
b]=>gr
een[
c]=>bl
ue[
d]=>y
ell
ow[
e]=>r
ed[
f]=>gr
een[
g]=>bl
ue)
Vi
ewAnswer
Answer
:a
Expl
anati
on:Thefunct
ionarr
ay_i
nter
sect()compar
est
hevaluesoft
wo(ormore)arr
ays,
andr et
urnst
he
matches.So,i
ntheaboveprogr
am valuesofa1anda2wi
l
l becomparedandt
hev al
uespresenti
nboth
thear
rayswil
lbetheretur
ned.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=ar
ray
(12,
5,2)
;
echo(
arr
ay_
product
($a)
);
?
>
a)024
b)120
c)010
d)060
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thear
ray
_pr
oduct
()f
unct
ioncal
cul
atesandr
etur
nst
hepr
oductofanar
ray
.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=ar
ray
("a"=>"
Jaguar
","
b"=>"
LandRov
er"
,
"
c"=>"
Audi
","
d"=>"
Maser
att
i"
);
echoar
ray
_sear
ch(
"Audi
",$a)
;
?
>
a)a
b)b
c)c
d)d
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Thear
ray
_sear
ch(
)funct
ionsear
chesf
ort
heel
ementandr
etur
nst
hekeyoft
hatel
ement
.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$ci
ty_
west=ar
ray
("NYC"
,"London"
);
$ci
ty_
east=ar
ray
("Mumbai
","
Bei
j
ing"
);
pr
int
_r(
arr
ay_
repl
ace(
$ci
ty_
west
,$ci
ty_
east
));
?
>
a)Ar
ray([
1]=>Mumbai
[0]=>Bei
j
ing)
b)Ar
ray([
0]=>NYC[
1]=>London)
c)Ar
ray([
1]=>NYC[
0]=>London)
d)Ar
ray([
0]=>Mumbai
[1]=>Bei
j
ing)
Vi
ewAnswer
Answer
:d
Explanat
ion:
Thef uncti
onarray
_repl
ace(
)repl
acestheval
uesoft
hef
irstarr
aywit
htheval
uesf r
om
fol
lowingarr
ays.So,intheaboveprogr
am theval
uesofci
ty_
westwi
l
lber epl
acedwit
hcit
y_east.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$peopl
e=ar
ray
("Pet
er"
,"Susan"
,"Edmund"
,"Lucy
");
echopos(
$peopl
e);
?
>
a)Lucy
b)Pet
er
c)Susan
d)Edmund
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thepos(
)functi
onr
eturnstheval
ueoft
hecur
rentel
ementi
nanar
ray
,andsi
nceno
oper
ati
onhasbeendone,t
hecur
rentelementi
sthef
ir
stel
ement.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$number=r
ange(
0,5)
;
pr
int
_r(
$number
);
?
>
a)Ar
ray([
0]=>0[
1]=>1[
2]=>2[
3]=>3[
4]=>4[
5]=>5)
b)Ar
ray([
0]=>0[
1]=>0[
2]=>0[
3]=>0[
4]=>0[
5]=>0)
c)Ar
ray([
0]=>5[
1]=>5[
2]=>5[
3]=>5[
4]=>5[
5]=>5)
d)Ar
ray([
0]=>0[
5]=>5)
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Ther
ange(
)funct
ioncr
eat
esanar
raycont
aini
ngar
angeofel
ement
s.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$ar
ray=ar
ray
("r
ed"
,"gr
een"
);
ar
ray
_push(
$ar
ray
,"bl
ue"
,"y
ell
ow"
);
pr
int
_r(
$ar
ray
);
?
>
a)Ar
ray([
0]=>r
ed[
1]=>gr
een[
2]=>bl
ue[
3]=>y
ell
ow)
b)Ar
ray([
0]=>bl
ue[
1]=>y
ell
ow[
2]=>r
ed[
3]=>gr
een)
c)Ar
ray([
0]=>r
ed[
1]=>gr
een)
d)Ar
ray([
0]=>bl
ue[
1]=>y
ell
ow)
Vi
ewAnswer
Answer
:a
Expl
anat
ion:Thef
unct
ionar
ray
_push()i
nsert
soneormoreelement
stot
heendofanar
ray
.So,
int
he
abovepr
ogram bl
ueandyel
l
owwi l
lbeinser
tedaf
terpr
evi
ousval
ues.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$age=ar
ray
("Har
ry"=>"
21"
,"Ron"=>"
19"
,"Mal
foy
"=>"
23"
);
ksor
t($age)
;
f
oreach(
$ageas$x=>$x_
val
ue)
{
echo"
Key
=".$x."
,Val
ue=".$x_
val
ue;
echo"
<br
>";
}
?
>
a)
Key=Har
ry,
Val
ue=21
Key=Ron,
Val
ue=21
Key=Mal
foy
,Val
ue=23
b)
Key=Har
ry,
Val
ue=21
Key=Ron,
Val
ue=19
Key=Mal
foy
,Val
ue=23
c)
Key=Har
ry,
Val
ue=21
Key=Mal
foy
,Val
ue=23
Key=Ron,
Val
ue=19
d)
Key=Ron,
Val
ue=19
Key=Har
ry,
Val
ue=21
Key=Mal
foy
,Val
ue=23
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Theksor
t()f
unct
ionsor
tsanassoci
ati
vear
rayi
nascendi
ngor
der
,accor
dingt
othekey
.
PHPQuest
ions&Answer
s–Basi
csofObj
ect
-Or
ient
edPHP-1
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Basi
csofObj
ect
-Or
ient
ed
PHP”.
1.Thepract
iceofsepar
ati
ngtheuserf
rom t
het
ruei
nnerwor
kingsofanappl
i
cat
iont
hroughwel
l
-known
i
nterf
acesisknownas_ _
____
___
a)Pol
ymor
phi
sm
b)I
nher
it
ance
c)Encapsul
ati
on
d)Abst
ract
ion
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Inobj
ect
-or
ient
edPHPencapsul
ati
oni
saconceptofwr
appi
nguporbi
ndi
ngupt
hedat
a
membersandmethodsi
nasi ngl
emodul
e.
2.Whichoft
hefol
lowi
ngterm or
igi
nat
esfrom theGreeklanguaget
hatmeans“
hav
ingmul
ti
plef
orms,
”
def
inesOOP’sabi
l
ityt
oredef
ine,
aclass’
scharacter
ist
ics?
a)Abst
ract
ion
b)Pol
ymor
phi
sm
c)I
nher
it
ance
d)Di
ff
erent
ial
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thewordpolymor
phism i
sderi
vedfr
om Gr
eekwor
dpolywhi
chmeans“many
”and
morphi
sm whichmeanst
hepropert
ywhichhel
psustoassi
gnmor
ethanonepr
oper
ty.
3.Thepr
act
iceofcr
eat
ingobj
ect
sbasedonpr
edef
inedcl
assesi
sof
tenr
efer
redt
oas_
___
___
___
___
_
a)cl
asscr
eat
ion
b)obj
ectcr
eat
ion
c)obj
ecti
nst
ant
iat
ion
d)cl
assi
nst
ant
iat
ion
Vi
ewAnswer
Answer
:d
Explanati
on:Inobject
-ori
ent
edprogrammi ng,cl
assesaret
hebluepr
intsofphpobject
s.Cl assesdonot
actuall
ybecomeobj ectsunt
ili
nstanti
ati
onisdone.Whensomeonei nstant
iat
esaclass,itcreat
esan
i
nstanceofi t
,thuscreati
ngtheobject
.Inotherwords,
inst
ant
iati
oni
st heprocessofcreatinganinst
ance
ofanobj ecti
nmemor y.
4.Whi
choneoft
hef
oll
owi
ngpr
oper
tyscopesi
snotsuppor
tedbyPHP?
a)f
ri
endl
y
b)f
inal
c)publ
i
c
d)st
ati
c
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
PHPsuppor
tsf
ivecl
asspr
oper
tyscopes:
publ
i
c,pr
ivat
e,pr
otect
ed,
final
andst
ati
c.
5.Whi
choneoft
hef
oll
owi
ngcanbeusedt
oinst
ant
iat
eanobj
ecti
nPHPassumi
ngcl
assnamet
obeFoo?
a)$obj
=new$f
oo;
b)$obj
=newf
oo;
c)$obj
=newf
oo(
);
d)obj
=newf
oo(
);
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Tocr
eat
eanewobj
ecti
nPHPwecanuset
henewst
atementt
oinst
ant
iat
eacl
ass.
6.Whi
choneoft
hef
oll
owi
ngi
sther
ightwayt
odef
ineaconst
ant
?
a)const
antPI=“
3.1415”
;
b)const$PI=“
3.1415”
;
c)const
antPI=‘
3.1415’
;
d)constPI=‘
3.1415’
;
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Classconst
ant
sar
ecr
eat
edl
i
ke:
constNAME=‘
VALUE’
;
7.Whi
choneoft
hef
oll
owi
ngi
sther
ightwayt
ocal
lacl
assconst
ant
,gi
vent
hatt
hecl
assi
smat
hFunct
ion?
a)echoPI
;
b)echomat
hFunct
ion-
>PI
;
c)echomat
hFunct
ion:
:
PI;
d)echomat
hFunct
ion=PI
;
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
TheScopeResolut
ionOper
ator“
::
”isat
okent
hatal
l
owsaccesst
ost
ati
c,const
ant
,and
over
ri
ddenproper
ti
esormethodsofacl
ass.
8.Whi
choneoft
hef
oll
owi
ngi
sther
ightwayt
oinv
okeamet
hod?
a)$obj
ect
->met
hodName(
);
b)obj
ect
->met
hodName(
);
c)obj
ect
::
met
hodName(
);
d)$obj
ect
::
met
hodName(
);
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
“->”i
sady
nami
ccl
assmet
hodi
nvocat
ioni
nPHP.
9.Whi
choft
hef
oll
owi
ngi
s/ar
ether
ightwayt
odecl
areamet
hod?
i
)funct
ionf
unct
ionName(
){f
unct
ionbody}
i
i
)scopef
unct
ionf
unct
ionName(
){f
unct
ionbody}
i
i
i)met
hodmet
hodName(
){met
hodbody}
i
v)scopemet
hodmet
hodName(
){met
hodbody}
a)Onl
yii
)
b)Onl
yiv
)
c)i
)andi
i
)
d)i
i
i)andi
v)
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Incaseofpubli
cmethods,
youcanf
orgoexpl
i
cit
lydecl
ari
ngt
hescopeandj
ustdecl
aret
he
methodl
ikeyouwoul
daf uncti
on.
10.Whi
choft
hef
oll
owi
ngmet
hodscopesi
s/ar
enotsuppor
tedbyPHP?
i
)pr
ivat
e
i
i
)fr
iendl
y
i
i
i)st
ati
c
i
v)abst
ract
a)Onl
yii
)
b)Onl
yiv
)
c)i
i
)andi
v)
d)Onl
yi)
Vi
ewAnswer
Answer
:a
Expl
anat
ion:PHPsupport
ssi
xmet
hodscopes:
publ
i
c,pr
ivat
e,f
inal
,st
ati
c,pr
otect
edandabst
ract
.Buti
t
doesnotsuppor
tfr
iendl
y
PHPQuest
ions&Answer
s–Basi
csofObj
ect
-Or
ient
edPHP-2
Thi
ssetofPHPQuest
ionsandAnswer
sforExper
iencedpeopl
efocuseson“
Basi
csofObj
ect
-Or
ient
ed
PHP-2”
.
1.Whi
chmet
hodscopepr
event
samet
hodf
rom bei
ngov
err
iddenbyasubcl
ass?
a)Abst
ract
b)Pr
otect
ed
c)Fi
nal
d)St
ati
c
Vi
ewAnswer
Answer
:c
Expl
anati
on:Whenwedeclar
eamet hodisasf
inal
theniti
snotpossi
blet
ooverr
idet
hatmet
hod.
Methodsshoul
dnotbeoverr
iddenduetosomesecuri
tyoranyot
herr
easons.
2.Whi
choft
hef
oll
owi
ngst
atement
sis/
aret
rueaboutConst
ruct
orsi
nPHP?
i
)PHP4i
ntr
oducedcl
assconst
ruct
ors.
i
i
)Const
ruct
orscanacceptpar
amet
ers.
i
i
i)Const
ruct
orscancal
lcl
assmet
hodsorot
herf
unct
ions.
i
v)Cl
assconst
ruct
orscancal
lonot
herconst
ruct
ors.
a)i
i
)
b)i
i
)andi
i
i)
c)i
),i
i
),i
i
i)andi
v)
d)i
i
),i
i
i)andi
v)
Vi
ewAnswer
Answer
:c
Expl
anati
on: I
facl
assnameandt hef
unct
ionnamei ssimi
l
arthenthefuncti
onisknownasconstructor.
Const
ructorisaut
omati
cal
lycal
ledwhenanobjectwil
lbei
nit
ial
i
zed.Construct
orscanacceptpar
amet ers.
Const
ructorscancal
lcl
assmethodsorot
herfuncti
ons.Cl
assconstr
uctorscancal
lonotherconstr
uctors.
3.PHPr
ecogni
zesconst
ruct
orsbyt
hename_
___
___
__
a)cl
assname(
)
b)_
const
ruct
()
c)f
unct
ion_
const
ruct
()
d)f
unct
ion_
_const
ruct
()
Vi
ewAnswer
Answer
:d
Expl
anat
ion:Adoubl
eunderscorefoll
owedbyt heconst
ructkey
wor
d.I
tssy
ntaxi
sfunct
ion_
_const
ruct
([ar
gument1,ar
gument
2,….
.]){ClassIni
ti
ali
zat
ioncode}.
4.Whi
chv
ersi
onofPHPi
ntr
oducedt
hei
nst
anceofkey
wor
d?
a)PHP4
b)PHP5
c)PHP5.
3
d)PHP6
Vi
ewanswer
Answer
:b
Expl
anat
ion:
Usi
nginst
anceofkey
wordwecandet er
minewhet
heranobjecti
saninst
anceofacl
ass.
$manager=newEmployee(
)…if($manageri
nst
anceofEmpl
oyee)echo“Tr
ue”;
5.Whi
choneoft
hef
oll
owi
ngf
unct
ionsi
susedt
odet
ermi
newhet
heracl
assexi
sts?
a)exi
st(
)
b)exi
st_
class(
)
c)cl
ass_
exi
st(
)
d)_
_exi
st(
)
Vi
ewAnswer
Answer
:c
Expl
anati
on:Theclass_
exi
st()f
uncti
onret
urnst
rueorf
alseaccor
dingt
owhet
hert
hecl
assexi
stswi
thi
n
thecur
rent
lyexecuti
ngscr
iptcont
ent.
6.Whi
choneoft
hef
oll
owi
ngf
unct
ionsi
susedt
odet
ermi
neobj
ectt
ype?
a)obj
_ty
pe(
)
b)t
ype(
)
c)i
s_a(
)
d)i
s_obj
()
Vi
ewAnswer
Answer
:c
Expl
anati
on:
Theis_
a()functi
onret
urnstr
ueifobjectbel
ongst
oacl
asst
ypeori
fitbel
ongst
oacl
asst
hat
i
sachildoft
hatcl
ass.Orelsefal
seisret
urned.
7.Whi
choneoft
hef
oll
owi
ngkey
wor
disusedt
oinher
itoursubcl
assi
ntoasuper
class?
a)ext
ends
b)i
mpl
ement
s
c)i
nher
it
d)i
ncl
ude
Vi
ewAnswer
Answer
:a
Expl
anati
on:Whenweext
endacl
asst
hent
hesubcl
asswi
l
linher
ital
lthepubl
i
candpr
otect
edmet
hods
fr
om thepar
entcl
ass.
Thekey
wor
dimpl
ement
sar
eusedwi
thi
nter
faces.Wi
thi
nher
it
ance,
weuset
hekey
wor
dext
ends.
8.I
nthePHPcodegi
venbel
ow,
whati
s/ar
ethepr
oper
ti
es?
<?
php
cl
assExampl
e
{
publ
i
c$name;
f
unct
ionSampl
e()
{
echo"
Thi
sisanexampl
e";
}
}
?
>
a)echo“
Thi
sisanexampl
e”;
b)publ
i
c$name;
c)cl
assExampl
e
d)f
unct
ionsampl
e()
Vi
ewAnswer
Answer
:b
Expl
anat
ion:Abov
ecodeisanexampleof‘cl
asses’i
nPHP.Classesarethebl
uepr
int
sofobj
ects.Cl
asses
aret
heprogrammer-
def
ineddat
atype,whichincl
udest
helocalmethodsandthel
ocalv
ari
abl
es.Classi
s
acol
lect
ionofobj
ect
swhichhaspropert
iesandbehavi
our
.
adv
ert
isement
9.Whi
chkey
wor
disusedt
oref
ert
opr
oper
ti
esormet
hodswi
thi
nthecl
assi
tsel
f?
a)pr
ivat
e
b)publ
i
c
c)pr
otect
ed
d)$t
his
Vi
ewAnswer
Answer
:d
Expl
anati
on:I
nPHP,thesel
fand‘thi
s’key
wor dar
eusedtoref
ertheclassmember
swi
thi
nthescopeofa
cl
assit
self
.Thecl
assmember scanbeeithervar
iabl
esorf
uncti
ons.
10.Whichkey
wor
dallowscl
assmember s(
met
hodsandpr
oper
ti
es)t
obeusedwi
thoutneedi
ngt
o
i
nstant
iat
eanewinst
anceofthecl
ass?
a)pr
otect
ed
b)f
inal
c)st
ati
c
d)pr
ivat
e
Vi
ewAnswer
Answer
:c
Explanat
ion:Somet imesiti
sv er
yhandytoaccessthemet
hodsandproper
ti
esinter
msofacl assr
ather
thananobj ect.Butthi
scanbedonet hr
oughstati
ckeywor
d.Anymethoddecl
aredas‘st
ati
c’canbe
accessedwi thoutthecreat
ionofanobject
PHPQuest
ions&Answer
s–St
ri
ngsandRegul
arExpr
essi
ons–1
ThissetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Str
ingsandRegul
ar
Expressi
ons–1”
.
1.PHPhasl
ongsuppor
tedt
wor
egul
arexpr
essi
oni
mpl
ement
ati
onsknownas_
___
___and_
___
___
i
)Per
l
i
i
)PEAR
i
i
i)Pear
l
i
v)POSI
X
a)i
)andi
i
)
b)i
i
)andi
v)
c)i
)andi
v)
d)i
i
)andi
i
i)
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
None.
2.Whi
choneoft
hef
oll
owi
ngr
egul
arexpr
essi
onmat
chesanyst
ri
ngcont
aini
ngzer
ooronep?
a)p+
b)p*
c)P?
d)p#
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
None.
3.[
:al
pha:
]canal
sobespeci
fi
edas.
.
a)[
A-Za-
z0-
9].
b)[
A-za-
z].
c)[
A-z]
.
d)[
a-z]
.
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
[:
alpha:
]isnot
hingbutLower
caseandupper
caseal
phabet
ical
char
act
ers.
4.Howmanyf
unct
ionsdoesPHPof
ferf
orsear
chi
ngst
ri
ngsusi
ngPOSI
Xst
yler
egul
arexpr
essi
on?
a)7
b)8
c)9
d)10
Vi
ewAnswer
Answer
:a
Explanat
ion:
ereg(
),er
eg_
repl
ace(
),er
egi
()
,er
egi
_repl
ace(
),spl
i
t()
,spl
i
ti(
),andsql
_regcase(
)ar
ethe
functi
onsoffer
ed.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$user
name="
jasoN"
;
i
f(er
eg(
"([
^a-
z])
",
$user
name)
)
echo"
User
namemustbeal
ll
ower
case!
";
el
se
echo"
User
namei
sal
ll
ower
case!
";
?
>
a)Er
ror
b)User
namemustbeal
ll
ower
case!
c)User
namei
sal
ll
ower
case!
d)NoOut
puti
sret
urned
Vi
ewAnswer
Answer
:b
Explanat
ion:Becauset
heprov
idedusernamei
snotal
ll
owercase,er
eg(
)will
notret
urnFALSE(
inst
ead
ret
urningthelengt
hofthematchedst
ri
ng,whi
chPHPwill
treatasTRUE),
causi
ngthemessagetoout
put
.
6.POSI
Ximpl
ement
ati
onwasdepr
ecat
edi
nwhi
chv
ersi
onofPHP?
a)PHP4
b)PHP5
c)PHP5.
2
d)PHP5.
3
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
None.
7.POSI
Xst
andsf
or
a)Por
tabl
eOper
ati
ngSy
stem I
nter
facef
orUni
x
b)Por
tabl
eOper
ati
ngSy
stem I
nter
facef
orLi
nux
c)Por
tat
iveOper
ati
ngSy
stem I
nter
facef
orUni
x
d)Por
tat
iveOper
ati
ngSy
stem I
nter
facef
orLi
nux
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
None.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$t
ext="
thi
sis\
tsomet
extt
hat
\nwemi
ghtl
i
ket
opar
se.
";
pr
int
_r(
spl
i
t("
[\
n\t
]"
,$t
ext
));
?
>
a)t
hisi
ssomet
extt
hatwemi
ghtl
i
ket
opar
se.
b)Ar
ray([
0]=>somet
extt
hat[
1]=>wemi
ghtl
i
ket
opar
se.)
c)Ar
ray([
0]=>t
hisi
s[1]=>somet
extt
hat[
2]=>wemi
ghtl
i
ket
opar
se.)
d)[
0]=>t
hisi
s[1]=>somet
extt
hat[
2]=>wemi
ghtl
i
ket
opar
se.
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Thespli
t(
)funct
iondi
vi
desastri
ngint
ov ar
iousel
ements,
wit
htheboundar
iesofeach
el
ementbasedontheoccurr
enceofadef
inedpatt
ernwithi
nthest
ri
ng.
adv
ert
isement
9.Whi
choft
hef
oll
owi
ngwoul
dbeapot
ent
ial
mat
chf
ort
hePer
l-
basedr
egul
arexpr
essi
on/
fo{
2,4}
/?
i
)fol
i
i
)fool
i
i
i)f
ooool
i
v)f
ooooool
a)Onl
yi)
b)i
i
)andi
i
i)
c)i
),i
i
i)andi
v)
d)i
)andi
v)
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thi
smat
chesff
oll
owedbyt
wot
ofouroccur
rencesofo.
10.Whi
chamongt
hef
oll
owi
ngi
s/ar
enotamet
achar
act
er?
i
)\a
i
i
)\A
i
i
i)\
b
i
v)\
B
a)Onl
yi)
b)i
)andi
i
i)
c)i
i
),i
i
i)andi
v)
d)i
i
)andi
v)
Vi
ewAnswer
Answer
:a
Expl
anati
on:
/A,/
band/ Bar
emetacharact
ers.\A:
Matchesonl
yatthebegi
nni
ngoft
hest
ri
ng.\
b:
Matchesawordboundar
y.\
B:Matchesanythi
ngbutawordboundary
.
PHPQuest
ions&Answer
s–St
ri
ngsandRegul
arExpr
essi
ons–2
Thi
ssetofPHPInter
viewQuest
ionsandAnswer
sforExper
iencedpeopl
efocuseson“
Str
ingsand
Regul
arExpr
essi
ons–2” .
1.Howmanyf unct
ionsdoesPHPof
ferf
orsear
chi
ngandmodi
fyi
ngst
ri
ngsusi
ngPer
l-
compat
ibl
eregul
ar
expr
essi
ons.
a)7
b)8
c)9
d)10
Vi
ewAnswer
Answer
:b
Explanati
on:Thefuncti
onsarepreg_
fil
ter(
),pr
eg_grep(
),preg_
mat
ch(
),pr
eg_
mat
ch_
all
()
,pr
eg_
quot
e()
,
preg_repl
ace()
,pr
eg_replace_
cal
l
back(),andpreg_spl
it
().
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$f
oods=ar
ray
("past
a",
"st
eak"
,"f
ish"
,"pot
atoes"
);
$f
ood=pr
eg_
grep(
"/^
s/"
,$f
oods)
;
pr
int
_r(
$food)
;
?
>
a)Ar
ray([
0]=>past
a[1]=>st
eak[
2]=>f
ish[
3]=>pot
atoes)
b)Ar
ray([
3]=>pot
atoes)
c)Ar
ray([
1]=>st
eak)
d)Ar
ray([
0]=>pot
atoes)
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Thi
sfunct
ioni
susedt
osear
chanar
rayf
orf
oodsbegi
nni
ngwi
ths.
3.Saywehav
etwocompar
etwost
ri
ngswhi
choft
hef
oll
owi
ngf
unct
ion/
funct
ionscany
ouuse?
i
)st
rcmp(
)
i
i
)st
rcasecmp(
)
i
i
i)st
rspn(
)
i
v)st
rcspn(
)
a)i
)andi
i
)
b)i
i
i)andi
v)
c)Noneoft
hement
ioned
d)Al
loft
hement
ioned
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
All
oft
hef
unct
ionsment
ionedabov
ecanbeusedt
ocompar
est
ri
ngsi
nsomeort
heot
her
way.
4.Whi
choneoft
hef
oll
owi
ngf
unct
ionswi
l
lconv
ertast
ri
ngt
oal
lupper
case?
a)st
rt
oupper
()
b)upper
case(
)
c)st
r_upper
case(
)
d)st
rupper
case(
)
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Itspr
otot
ypef
oll
owsst
ri
ngst
rtoupper
(st
ri
ngst
r).
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$t
it
le="
O'mal
l
eywi
nst
heheav
ywei
ghtchampi
onshi
p!"
;
echoucwor
ds(
$ti
tl
e);
?
>
a)O’
Mal
l
eyWi
nsTheHeav
ywei
ghtChampi
onshi
p!
b)O’
mal
l
eyWi
nsTheHeav
ywei
ghtChampi
onshi
p!
c)O’
Mal
l
eywi
nst
heheav
ywei
ghtchampi
onshi
p!
d)o’
mal
l
eywi
nst
heheav
ywei
ghtchampi
onshi
p!
Vi
ewAnswer
Answer
:d
Explanat
ion:Theucwords()funct
ioncapi
tal
i
zest
hef
ir
stl
ett
erofeachwor
dinast
ri
ng.I
tspr
otot
ype
fol
lows:stri
ngucwords(st
ringstr
).
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echost
r_pad(
"Sal
ad"
,5)
."i
sgood.
";
?
>
a)Sal
adSal
adSal
adSal
adSal
adi
sgood
b)i
sgoodSal
adSal
adSal
adSal
adSal
ad
c)i
sgoodSal
ad
d)Sal
adi
sgood
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Thest
r_pad(
)funct
ionpadsast
ri
ngwi
thaspeci
fi
ednumberofchar
act
ers.
adv
ert
isement
7.Whi
choneofthef
oll
owi
ngf
unct
ionscanbeusedt
oconcat
enat
ear
rayel
ement
stof
orm asi
ngl
e
del
imi
tedst
ri
ng?
a)expl
ode(
)
b)i
mpl
ode(
)
c)concat
()
d)concat
enat
e()
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
None.
8.Whichoneoft
hef
oll
owi
ngf
unct
ionsf
indst
hel
astoccur
renceofast
ri
ng,
ret
urni
ngi
tsnumer
ical
posi
ti
on?
a)st
rl
ast
pos(
)
b)st
rpos(
)
c)st
rl
ast
()
d)st
rrpos(
)
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
None.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$aut
hor="
nachi
ket
h@exampl
e.com"
;
$aut
hor=st
r_r
epl
ace(
"a"
,"
@",
$aut
hor
);
echo"
Cont
actt
heaut
horoft
hisar
ti
cl
eat$aut
hor
."
;
?
>
a)Cont
actt
heaut
horoft
hisar
ti
cl
eatnachi
ket
h@ex@mpl
e.com
b)Cont
@ctt
he@ut
horoft
his@r
ti
cl
e@tn@chi
ket
h@ex@mpl
e.com
c)Cont
actt
heaut
horoft
hisar
ti
cl
eatn@chi
ket
h@ex@mpl
e.com
d)Er
ror
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Thest
r_r
epl
ace(
)funct
ioncasesensi
ti
vel
yrepl
acesal
li
nst
ancesofast
ri
ngwi
thanot
her
.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$ur
l="
nachi
ket
h@exampl
e.com"
;
echol
tr
im(
str
str
($ur
l,"
@")
,"
@")
;
?
>
a)nachi
ket
h@exampl
e.com
b)nachi
ket
h
c)nachi
ket
h@
d)exampl
e.com
Vi
ewAnswer
Answer
:d
Explanat
ion:
Thestrst
r()f
unct
ionr
etur
nst
her
emai
nderofast
ri
ngbegi
nni
ngwi
tht
hef
ir
stoccur
renceofa
predefi
nedstr
ing.
PHPQuest
ions&Answer
s–HTMLFor
ms
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
HTMLFor
ms”
.
1.Whi
cht
wopr
edef
inedv
ari
abl
esar
eusedt
oret
ri
evei
nfor
mat
ionf
rom f
orms?
a)$GET&$SET
b)$_
GET&$_
SET
c)$_
_GET&$_
_SET
d)GET&SET
Vi
ewAnswer
Answer
:b
Expl
anati
on:Theglobal
v ar
iabl
es$_GETi
susedtocol
l
ectform dat
aaft
ersubmi
tti
nganHTMLf
orm wi
th
themethod=”get
”.Thevari
able$_
SETisal
sousedtor
etr
ievei
nformat
ionfr
om f
orms.
2.Theat
tackwhi
chinvol
vest
hei
nser
ti
onofmal
i
ciouscodei
ntoapagef
requent
edbyot
heruser
sis
knownas____
___
___
_ _
___
a)basi
csql
inj
ect
ion
b)adv
ancedsql
inj
ect
ion
c)cr
oss-
sit
escr
ipt
ing
d)scr
ipt
ing
Vi
ewAnswer
Answer
:c
Explanat
ion:Thecr oss-sitescri
pti
ngatt
ackisamongoneofthetopfi
vesecuri
tyatt
ackscarri
edout
acrosstheInternet.I
tisal soknownasXSS, thi
sat
tacki
saty
peofcodei nj
ecti
onattackwhichismade
possibl
ebyi ncorrect
lyv al
idati
nguserdata,
whichusual
l
yget
sinsert
edintothepagethroughawebform
orusinganal t
eredhy per l
i
nk.
3.Wheny
ouuset
he$_
GETv
ari
abl
etocol
l
ectdat
a,t
hedat
aisv
isi
blet
o__
___
___
___
a)none
b)onl
yyou
c)ev
ery
one
d)sel
ect
edf
ew
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Theinformat
ionsentf
rom afor
m wi
tht
hemet
hodGETi
svi
sibl
etoev
ery
onei
.e.al
lvar
iabl
e
namesandvaluesaredi
splay
edintheURL.
4.Wheny
ouuset
he$_
POSTv
ari
abl
etocol
l
ectdat
a,t
hedat
aisv
isi
blet
o__
___
___
___
a)none
b)onl
yyou
c)ev
ery
one
d)sel
ect
edf
ew
Vi
ewAnswer
Answer
:b
Expl
anat
ion:Theinf
ormat
ionsentfr
om afor
m wi
tht
hemethodPOSTi
sinv
isi
blet
oot
her
si.
e.al
l
names/v
aluesareembeddedwithi
nthebodyoft
heHTTPr
equest
.
5.Whi
chv
ari
abl
eisusedt
ocol
l
ectf
orm dat
asentwi
thbot
htheGETandPOSTmet
hods?
a)$BOTH
b)$_
BOTH
c)$REQUEST
d)$_
REQUEST
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
InPHPt
hegl
obal
var
iabl
e$_
REQUESTi
susedt
ocol
l
ectdat
aaf
tersubmi
tt
inganHTMLf
orm.
6.Whi
choneoft
hef
oll
owi
ngshoul
dnotbeusedwhi
l
esendi
ngpasswor
dsorot
hersensi
ti
vei
nfor
mat
ion?
a)GET
b)POST
c)REQUEST
d)NEXT
Vi
ewAnswer
Answer
:a
Explanati
on:Thei
nformat
ionsentf
rom afor
m wit
ht hemethodGETisvi
sibl
etoever
yonei
.e.al
lvar
iabl
e
namesandv al
uesaredi
splay
edintheURL.So,
itshouldnotbeusedwhi
lesendi
ngpasswordsorot
her
sensiti
veinf
ormati
on.
7.Whi
chf
unct
ioni
susedt
oremov
eal
lHTMLt
agsf
rom ast
ri
ngpassedt
oaf
orm?
a)r
emov
e_t
ags(
)
b)st
ri
p_t
ags(
)
c)t
ags_
str
ip(
)
d)t
ags_
remov
e()
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thef
unct
ionst
ri
p_t
ags(
)isusedt
ost
ri
past
ri
ngf
rom HTML,
XML,
andPHPt
ags.
8.Whatwi
l
lbet
hev
alueoft
hev
ari
abl
e$i
nputi
nthef
oll
owi
ngPHPcode?
<?
php
$i
nput="
Swapna<t
d>Lawr
ence</
td>y
ouar
ereal
l
y<i
>pr
ett
y</
i>!
";
$i
nput=st
ri
p_t
ags(
$input
,"
<i></
i>"
);
echo$i
nput
;
?
>
a)SwapnaLawr
encey
ouar
ereal
l
ypr
ett
y!
b)Swapna<t
d>Lawr
ence</
td>y
ouar
ereal
l
y<i
>pr
ett
y</
i>!
c)Swapna<t
d>Lawr
ence</
td>y
ouar
ereal
l
ypr
ett
y!
d)SwapnaLawr
encey
ouar
ereal
l
y<i
>pr
ett
y</
i>!
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Ital
i
ctags<i
></
i>mi
ghtbeal
l
owabl
e,butt
abl
etags<t
d></
td>coul
dpot
ent
ial
l
ywr
eakhav
oc
onapage.
adv
ert
isement
9.Tov
ali
dat
eanemai
laddr
ess,
whi
chf
lagi
stobepassedt
othef
unct
ionf
il
ter
_var
()?
a)FI
LTER_
VALI
DATE_
EMAI
L
b)FI
LTER_
VALI
DATE_
MAI
L
c)VALI
DATE_
EMAI
L
d)VALI
DATE_
MAI
L
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
TheFI
LTER_
VALI
DATE_
EMAI
Lisusedt
oval
i
dat
esane-
mai
laddr
ess.
10.Howmanyv
ali
dat
ionf
il
ter
sli
keFI
LTER_
VALI
DATE_
EMAI
Lar
ecur
rent
lyav
ail
abl
e?
a)5
b)6
c)7
d)8
Vi
ewAnswer
Answer
:c
Explanat
ion:
Therearesev
enval
idati
onfil
ter
s.TheyareFI
LTER_VALIDATE_EMAIL,
FILTER_VALIDATE_
BOOLEAN,FILTER_VALIDATE_FLOAT,
FILTER_VALIDATE_
INT,FI
LTER_
VALI
DATE_
IP,
FILTER_VALIDATE_
REGEXP,FI
LTER_VALIDATE_URL.
PHPCodi
ngQuest
ionsandAnswer
s–Sy
ntax–1
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Synt
ax–1”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
"
Hel
l
oWor
ld"
?
>
a)Er
ror
b)Hel
l
oWor
ld
c)Not
hing
d)Mi
ssi
ngsemi
col
oner
ror
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Ify
ouneedt
oout
putsomet
hingont
othescr
eeny
ou’
l
lneedt
ouseechoorpr
int
_r.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
pr
int
_r"
Hel
l
owor
ld"
?
>
a)Er
ror
b)Hel
l
oWor
ld
c)Not
hing
d)Mi
ssi
ngsemi
col
oner
ror
Vi
ewAnswer
Answer
:a
Expl
anati
on:Thest
atementshoul
dbeprint_
r(‘Hel
loWorld’
)topr
intHel
l
owor
ld.Al
soi
fther
eisonl
yone
l
inethenther
eisnorequi
rementofasemicolon,buti
tisbett
ert
ouseit.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echo'
Hel
l
oWor
ld'
;
<ht
ml>
Hel
l
owor
ld
</
html
>
?
>
a)Hel
l
owor
ld
b)Hel
l
oWor
ldHel
l
oWor
ld
c)Hel
l
owor
ld
Hel
l
oWor
ld
d)Sy
ntaxEr
ror
Vi
ewAnswer
Answer
:d
Explanat
ion:
Par
seer
ror
:sy
ntaxer
ror
,unexpect
ed‘
<‘onl
i
ne2.Youcannotuset
heht
mlt
agi
nsi
dephp
tags.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
Echo"
Hel
l
oWor
ld1"
;
echo"Hel
l
owor
ld2"
;
ECHO"Hel
l
owor
ld3"
;
?
>
a)Hel
l
owor
ld1Hel
l
owor
ld2Hel
l
oWor
ld3
b)Hel
l
owor
ld1
Hel
l
owor
ld2
Hel
l
oWor
ld3
c)Er
ror
d)Hel
l
owor
ld1Hel
l
owor
ld3
Vi
ewAnswer
Answer
:a
Explanat
ion:
InPHP,
all
user
-def
inedf
unct
ions,
classes,
andkey
wor
ds(
e.g.i
f,el
se,
whi
l
e,echo,
etc.
)ar
e
case-i
nsensi
ti
ve.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or="
red"
;
echo"
$col
or"
;
echo"
$COLOR"
;
echo"
$Col
or"
;
?
>
a)r
edr
edr
ed
b)r
edr
ed
c)r
ed
d)Er
ror
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
InPHP,
all
var
iabl
esar
ecase-
sensi
ti
ve.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
#echo"
Hel
l
owor
ld"
;
echo"
#Hel
l
owor
ld"
;
?
>
a)#Hel
l
owor
ld
b)Hel
l
owor
ld#Hel
l
owor
ld
c)Hel
l
owor
ld
d)Er
ror
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
#isasi
ngl
eli
necomment
.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echo"
<i>Hel
l
oWor
ld</
i>"
?
>
a)Hel
l
owor
ld
b)Hel
l
owor
ldi
nit
ali
cs
c)Not
hing
d)Er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Youcanuset
agsl
i
kei
tal
i
cs,
bol
det
c.i
nsi
dephpscr
ipt
.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echo"
echo"
Hel
l
oWor
ld"
";
?
>
a)Hel
l
owor
ld
b)echo“
Hel
l
owor
ld”
c)echoHel
l
owor
ld
d)Er
ror
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Itwoul
dhav
epr
int
edecho“
Hel
l
owor
ld”i
fthest
atementwasecho“
echo\
”Hel
l
oWor
ld\
””;
.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
<?
php
echo"
Hel
l
owor
ld"
;
?
>
?
>
a)HELLOWORLD
b)Hel
l
owor
ld
c)Not
hing
d)Er
ror
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Youcannothav
ephpt
agsi
nsi
deaphpt
ag.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or=r
ed;
echo"
\$col
or"
;
?
>
a)r
ed
b)$col
or
c)\
red
d)Er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Topr
intr
edr
emov
ethe\
.
PHPCodi
ngQuest
ionsandAnswer
s–Sy
ntax–2
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Synt
ax–2”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
/
*
echo"
Hel
l
owor
ld"
;
*
/
?
>
a)Hel
l
owor
ld
b)Not
hing
c)Er
ror
d)/
*
Hel
l
owor
ld
*
/
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
/**
/isusedf
orcomment
ingmul
ti
plel
i
nes.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or=r
ed;
echo"
$col
or".r
ed;
?
>
a)r
edr
ed
b)r
ed
c)er
ror
d)not
hing
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Useofundef
inedconst
antr
ed.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or1=r
ed;
$col
or2=gr
een;
echo"
$col
or1"
."
$col
or2"
;
?
>
a)r
edgr
een
b)r
ed
c)gr
een
d)er
ror
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Ithast
obe$col
or1=“
red”
;and$col
or2=“
green”
;ther
efor
etheer
ror
.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or="
red"
;
$col
or="
green"
;
echo"
$col
or"
;
?
>
a)r
ed
b)gr
een
c)r
edgr
een
d)er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thev
ari
abl
econt
ainst
hel
astv
aluewhi
chhasbeenassi
gned.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or1="
red"
;
$col
or2="
green"
;
echo"
$col
or1"."
$col
or2"
;
?
>
a)r
ed
b)gr
een
c)r
edgr
een
d)r
edgr
een
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
The.oper
atori
susedt
ojoi
ntost
ri
ngs.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or1="
red"
;
$col
or2="
green"
;
echo"
$col
or1"+"
$col
or2"
;
?
>
a)r
edgr
een
b)r
edgr
een
c)0
d)er
ror
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
+oper
atordoesnotj
oinbot
hthest
ri
ngs.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or1="
red"
;
$col
or2="
red"
;
echo"
$col
or1"+"
$col
or2"
;
?
>
a)r
edgr
een
b)r
edgr
een
c)0
d)1
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
+doesnotr
etur
n1i
fthev
ari
abl
esar
eequal
.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or1="
red"
;
$col
or2="
1";
echo"
$col
or1"+"
$col
or2"
;
?
>
a)r
ed1
b)r
ed1
c)0
d)1
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
+justr
etur
nst
henumer
icv
alueev
ent
houghi
tisi
nsi
dedoubl
equot
es.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or1="
1";
$col
or2="
1";
echo"
$col
or1"+"
$col
or2"
;
?
>
a)11
b)2
c)0
d)1
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
+canbeusedt
oaddt
oint
egerv
alueswhi
char
eencl
osedbydoubl
e-quot
es.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$col
or1="
red"
;
$col
or2="
1";
$col
or3="
grey
"
echo"
$col
or1"+"
$col
or2"."
$col
or3"
;
?
>
a)1gr
ey
b)gr
ey
c)0
d)r
ed1gr
ey
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
+gi
vest
hev
alue1and.i
susedt
ogi
vej
oin1andgr
ey.
PHPCodi
ngQuest
ionsandAnswer
s–Var
iabl
es–1
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Var
iabl
es–1”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=5;
$y=10;
$z="
$x+$y
";
echo"
$z"
;
?
>
a)15
b)10+5
c)$z
d)$x+$y
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Var
iabl
ezwi
l
lst
ore10+5because10+5i
sgi
veni
ndoubl
e-quot
es.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=4;
$y=3;
$z=1;
echo"
$x=$x+$y+$z"
;
?
>
a)4=4+3+1
b)8
c)8=4+3+1
d)Er
ror
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Agai
nsi
ncet
hev
ari
abl
esar
einsi
dedoubl
equot
eswegett
hisr
esul
t.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=4;
$y=3
$z=1;
$z=$z+$x+$y
;
echo"
$z"
;
?
>
a)$z
b)15
c)8
d)1
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Nor
mal
addi
ti
onofv
ari
abl
esx,
yandzoccur
sandr
esul
tof8wi
l
lbedi
spl
ayed.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=3.
3;
$y=2;
echo$x%$y
;
?
>
a)0
b)1
c)2
d)Er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
%ist
hemodul
ooper
ator
.Unl
i
kei
nCwecanusei
tgetr
emi
nderorf
loat
ingpoi
ntnumber
sin
PHP.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=10;
$y=4;
$z=3;
echo$x%$y%$z;
?
>
a)0
b)1
c)2
d)Er
ror
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Theexpr
essi
oni
sconsi
der
edas(
$x%$y
)%zi
nthi
scase(
10%4)
%3whi
chi
s2.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=10;
$y=4;
$z=3;
echo(
$x%(
$y)+$z)
;
?
>
a)5
b)3
c)0
d)1
Vi
ewAnswer
Answer
:a
Expl
anat
ion:Theinner
mostbr
acketi
sev
aluat
edf
ir
st,
sincei
tcov
ersonl
yvar
iabl
eyi
tisasgoodasnot
usi
ngbrackets.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=30;
$y=20;
$z=10;
echo$x+$y-$z/(
$z-$y
);
?
>
a)41
b)-
4
c)-
5
d)51
Vi
ewAnswer
Answer
:d
Expl
anat
ion:Fir
st(
$z–$y)i
sev
aluat
edt
hen-
$z/
($z–$y
)isev
aluat
edt
hisr
esul
tsi
n1whi
chi
saddedt
o
$x+$ytherefor
eweget51.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=-
1;
$y=1;
$z=$x*$y+$z;
echo$z;
?
>
a)Undef
inedv
ari
abl
ez
b)-
1
c)Undef
inedv
ari
abl
ez
-
1
d)Noneoft
hement
ioned
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Sincet
hev
ari
abl
ezi
snotdef
inedi
tret
urnst
heer
roral
soi
ttakeszas0andr
etur
nst
he
val
ue-1.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=4;
$y=-
3;
$z=11;
echo4+$y*$z/$x;
?
>
a)4.
25
b)3.
25
c)-
3.25
d)-
4.25
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Fir
stt
he*iseval
uatedt
hen/f
oll
owedby+t
her
efor
ewecanr
ewr
it
ethi
sexpr
essi
onas4+(
(-
3*11)/4)whichr
esul
tsi
n-4.25.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=3.
5;
$y=2;
$z=2;
echo$x/$y/$z;
?
>
a)1.
75
b)0.
875
c)3.
5
d)Er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Fir
st$x/$yi
sev
aluat
edt
hent
hisi
sdi
vi
dedby$zt
her
efor
eweget0.
875.
PHPCodi
ngQuest
ionsandAnswer
s–Var
iabl
es–2
Thi
ssetofPHPTechni
cal
Int
erv
iewQuest
ions&Answer
sfocuseson“
Var
iabl
es–2”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
one=1;
t
wo=2;
t
hree=3;
f
our=4;
echo"
one/t
wo+t
hree/f
our
";
?
>
a)0.
75
b)0.
05
c)1.
25
d)Er
ror
Vi
ewAnswer
Answer
:d
Expl
anati
on:Vari
abl
esshoul
dst
artwi
tha$sy
mbol
,si
nceone,
two,
thr
ee,
fourdon’
tbegi
nwi
th$sy
mbol
we’l
lgetanerr
or.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$on$e=1;
$t
w$o=2;
$t
hre$e=3;
$f
ou$r=4;
echo"
$on$e/$t
w$o+$t
hre$e/$f
ou$r
";
?
>
a)0.
75
b)0.
05
c)1.
25
d)Er
ror
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Youcannotuset
he$i
nbet
weent
hev
ari
abl
ename.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$on_
e=1;
$t
w_o=2;
$t
hre_
e=3;
$f
ou_
r=4;
echo$on_
e/$t
w_o+$t
hre_
e/$f
ou_
r;
?
>
a)0.
75
b)0.
05
c)1.
25
d)Er
ror
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Youcanuse_i
nav
ari
abl
ename.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$On_
e=1;
$t
w_o=2;
$t
hre_
e=3;
$f
ou_
r=4;
echo$on_
e/$t
w_o+$t
hre_
e/$f
ou_
r;
?
>
a)0.
75
b)0.
05
c)1.
25
d)Er
ror
Vi
ewAnswer
Answer
:a
Expl
anati
on:
Sincethevar
iabl
eini
ti
ali
sedi
s$On_
eandt
hev
ari
abl
eint
heechost
atementi
s$on_
ethe
echostat
ementtr
eats$on_eas0;
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echo$r
ed;
?
>
a)0
b)Not
hing
c)Tr
ue
d)Er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Ther
ewi
l
lnoout
putr
etur
nedast
hev
ari
abl
e$r
eddoesnothol
danyv
alue.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$f
our
4=4;
$t
hree3=3;
$t
wo2=2;
echo$f
our
4+$t
hree3/$t
wo2-1;
?
>
a)4.
5
b)7
c)3.
5
d)Er
ror
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Youcanusenumber
sinav
ari
abl
ename.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$4f
our=4;
$3t
hree=3;
$2t
wo=2;
echo$4f
our+$3t
hree/$2t
wo-1;
?
>
a)4.
5
b)7
c)3.
5
d)Er
ror
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Avar
iabl
enamecannotst
artwi
thanumer
icv
alue.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
i
nt$one=1;
echo"
$one"
;
?
>
a)0
b)1
c)$one
d)Er
ror
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Unl
i
keot
herpr
ogr
ammi
ngl
anguagest
her
ear
enodat
aty
pesi
nPHP.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
v
ar$one=1;
v
ar$t
wo=2;
echo$one/$t
wo*$one/$t
wo*$t
wo;
?
>
a)1
b)0
c)0.
5
d)Er
ror
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Youcannotusev
arbef
oreav
ari
abl
ename.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$hel
l
o="
Hel
l
oWor
ld"
;
$by
e="
Bye"
;
echo$hel
l
o;"
$by
e";
?
>
a)Hel
l
oWor
ld
b)By
e
c)Hel
l
owor
ldBy
e
d)Er
ror
Vi
ewAnswer
Answer
:a
Expl
anat
ion:Si
ncet
herei
sasemi-
col
oni
nbetween$hel
loand$by
e,t
hel
i
neendsat$hel
l
o.Howev
er
$byewouldhavepr
int
edi
faechowaspr
esentbef
ore“
$bye”.
PHPCodi
ngQuest
ionsandAnswer
s–Var
iabl
es–3
Thi
ssetofPHPPr
obl
emsf
ocuseson“
Var
iabl
es–3”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x;
echo"
$x"
;
?
>
a)0
b)1
c)Not
hing
d)Er
ror
Vi
ewAnswer
Answer
:c
Expl
anati
on:Si
ncethevar
iabl
exi
snoti
nit
ial
i
sedi
tisnotst
ori
nganyv
alue,
ther
efor
enot
hingwi
l
lbe
pri
ntedonthescr
een.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=5;
{
$x=10;
echo"
$x"
;
}
echo"
$x"
;
?
>
a)1010
b)105
c)510
d)er
ror
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Var
iabl
exst
orest
hev
alue10andnot5.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=5;
{
echo"
$x"
;
}
?
>
a)0
b)5
c)Not
hing
d)Er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thev
ari
abl
exst
orest
hev
alue5andt
her
efor
ethev
alue5i
spr
int
edont
hescr
een.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=5;
f
unct
ionf
un(
)
{
echo"
$x"
;
}
f
un(
);
?
>
a)0
b)5
c)Not
hing
d)Er
ror
Vi
ewAnswer
Answer
:c
Explanat
ion:
Thev
ari
abl
exi
snotdef
inedi
nsi
det
hef
unct
ionf
un(
),t
her
efor
enot
hingi
spr
int
edont
he
screen.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=5;
f
unct
ionf
un(
)
{
$x=10;
echo"
$x"
;
}
f
un(
);
echo"
$x"
;
?
>
a)0
b)105
c)510
d)Er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Firstwhent
hef
unct
ioni
scal
l
edv
ari
abl
exi
sini
ti
ali
sedt
o10so10i
spr
int
edl
atert
hegl
obal
val
ue5ispri
nted.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=4;
$y=3;
f
unct
ionf
un(
$x=3,
$y=4)
{
$z=$x+$y
/$y
+$x;
echo"
$z"
;
}
echo$x;
echo$y
;
echo$z;
f
un(
$x,
$y)
;
?
>
a)43
b)943
c)349
d)439
Vi
ewAnswer
Answer
:d
Expl
anat
ion:Fi
rst
ly,t
hestat
ementsoutsi
det
hefuncti
onar
eprint
ed,si
ncezisnotdefi
nedi
t’
ll
nov
aluei
s
pri
ntedf
orz.Nextthefunct
ioni
scall
edandtheval
ueofzinsi
dethefunct
ioni
spri
nted.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=4;
$y=3;
f
unct
ionf
un(
$x,
$y)
{
$z=$x+$y/$y+$x;
echo"
$z"
;
}
echo$x;
echo$y
;
echo$z;
f
un(
3,4)
;
?
>
a)437
b)439
c)349
d)347
Vi
ewAnswer
Answer
:a
Explanati
on:I
tissameasabov
ebutt
hev
aluepassedi
ntot
hef
unct
ioni
s3,
4andnot4,
3.Ther
efor
ethe
di
fferenceinanswer
.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
f
unct
ionf
un(
$x,
$y)
{
$x=4;
$y=3;
$z=$x+$y/$y+$x;
echo"
$z"
;
}
f
un(
3,4)
;
?
>
a)7
b)9
c)0
d)Er
ror
Vi
ewAnswer
Answer
:b
Explanat
ion:
Value3,4ispassedt
othefuncti
onbutthati
slostbecausexandyar
eini
ti
ali
sedt
o4and3
i
nsidethefunct
ion.Ther
efor
ewegetthegivenresul
t.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=3,
4,5,
6;
echo"
$x"
;
?
>
a)3
b)4
c)6
d)Er
ror
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
InCy
ouwon’
tgetaner
rorbuti
nPHPy
ou’
l
lgetasy
ntaxer
ror
.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=10;
$b=4;
$c=f
un(
10,
4);
f
unct
ionf
un(
$a,
$b)
{
$b=3;
r
etur
n$a-$b+$b-$a;
}
echo$a;
echo$b;
echo$c;
?
>
a)104
b)410
c)1400
d)4100
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Thev
aluer
etur
nedf
rom t
hef
unct
ioni
s0,
andv
alueofai
s10,
val
ueofbi
s4andci
s0.
PHPCodi
ngQuest
ionsandAnswer
s–Oper
ator
s–1
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Oper
ator
s–1”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=10;
echo++$a;
echo$a++;
echo$a;
echo++$a;
?
>
a)11111213
b)11121213
c)11111212
d)11111112
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
++$ai
ncr
ement
saandt
henpr
int
sit
,$a++pr
int
sandt
heni
ncr
ement
s.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=12;
-
-$a;
echo$a++;
?
>
a)11
b)12
c)10
d)er
ror
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
The+oper
atordoesuni
onofar
ray
sint
hator
der
,thent
he===oper
atorcompar
eskeyand
val
uepai
rs.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x="
test
";
$y="
thi
s";
$z="
also"
;
$x.
=$y.
=$z;
echo$x;
echo$y
;
?
>
a)t
est
thi
sthi
sal
so
b)t
est
thi
s
c)t
est
thi
sal
sot
hisal
so
d)er
roratl
i
ne4
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Thex.
=yi
sashor
thandf
orx=x.
yandt
hisi
sev
aluat
edf
rom r
ightt
olef
t.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=1;
$y=2;
i
f(++$x==$y
++)
{
echo"
tr
ue"
,$y
,$x;
}
?
>
a)noout
put
b)t
rue23
c)t
rue22
d)t
rue33
Vi
ewAnswer
Answer
:b
Expl
anat
ion:xi
spr
eincr
ement
edandyi
sposti
ncr
ement
edt
husbot
har
e2i
nthei
fcondi
ti
on,
lat
eryi
s
i
ncrement.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$y=2;
$w=4;
$y*
=$w/
=$y
;
echo$y
,$w;
?
>
a)80.
5
b)44
c)82
d)42
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Expr
essi
oni
sev
aluat
edf
rom r
ightt
olef
t.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$y=2;
i
f($y
--==++$y
)
{
echo$y
;
}
?
>
a)2
b)1
c)3
d)noout
put
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Fir
st$y=2i
scompar
edt
oandt
hendecr
ement
ed,
theni
ncr
ement
edandcompar
edt
o$y=2.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$y=2;
i
f(*
*$y==4)
{
echo$y
;
}
?
>
a)4
b)2
c)er
roratl
i
ne2
d)noout
put
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
The*
*isnotav
ali
doper
ator
,onl
y++and—exi
st.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$y=2;
i
f(-
-$y==2|
|$yxor-
-$y
)
{
echo$y
;
}
?
>
a)1
b)0
c)2
d)noout
put
Vi
ewAnswer
Answer
:b
Explanat
ion:
–$y==2isf
alsebutyi
sdecr
ement
ed,
thexorgi
vest
ruei
fonl
yoneoft
heoper
andsar
etr
ue,
thus1xor0i st
rue.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$y=2;
i
f(-
-$y<>(
$y!
=$y
++)
)
{
echo$y
;
}
?
>
a)1
b)0
c)2
d)noout
put
Vi
ewAnswer
Answer
:b
Explanat
ion:
–$y==2isf
alsebutyi
sdecr
ement
ed,
thexorgi
vest
ruei
fonl
yoneoft
heoper
andsar
etr
ue,
thus1xor0i st
rue.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echo$x-
-!=++$x;
?
>
a)1
b)0
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:a
Expl
anat
ion:Aut
omat i
cal
l
yxisdecl
aredandi
nit
ial
i
zedt
o0,
thendecr
ement
edandcompar
edwi
thi
ts
i
ncrements,
thusret
urns1.
11.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$aut
h=1;
$st
atus=1;
i
f($r
esul
t=(
($aut
h==1)&&(
$st
atus!
=0)
))
{
pr
int"
resul
tis$r
esul
t<br/
>";
}
?
>
a)r
esul
tist
rue
b)r
esul
tis1
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Resul
tisx&&ywhi
chr
etur
ns1i
fbot
hxandyar
etr
ue.
PHPCodi
ngQuest
ionsandAnswer
s–Oper
ator
s–3
Thi
ssetofPHPQuest
ionsandAnswer
sforEnt
ranceexamsf
ocuseson“
Oper
ator
s–3”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echo5*9/3+9;
?
>
a)24
b)3.
7
c)3.
85
d)0
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Oper
atorpr
ecedenceor
dermustbef
oll
owed.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
echo5*9/3+9
?
>
a)24
b)3.
7
c)3.
85
d)0
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Oper
atorpr
ecedenceor
dermustbef
oll
owed.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0;
$j
=0;
i
f($i
&&(
$j=$i
+10)
){
echo"
tr
ue"
;
}
echo$j
;
?
>
a)10
b)0
c)t
rue0
d)t
rue10
Vi
ewAnswer
Answer
:b
Expl
anation:I
nifcondi
ti
onwhent
hef
ir
stcasei
s0andi
san&&oper
ati
ont
hent
hesecondcommandi
s
notexecuted.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=10;
$j
=0;
i
f($i
||(
$j=$i
+10)
){
echo"
tr
ue"
;
}
echo$j
;
?
>
a)20
b)t
rue0
c)0
d)t
rue20
Vi
ewAnswer
Answer
:b
Explanati
on:
Ini
fcondi
ti
onwhent
hef
ir
stcasei
s1andi
san|
|oper
ati
ont
hent
hesecondcommandi
snot
executed.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=1;
i
f($i
++&&(
$i==1)
)
pr
int
f("
Yes\
n$i
")
;
el
se
pr
int
f("
No\
n$i
")
;
?
>
a)No2
b)Yes1
c)Yes2
d)No1
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Thef
ir
stcondi
ti
onr
etur
nst
rueandi
ncr
ement
sbutt
hesecondcondi
ti
oni
sfal
se.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=1;
$b=3;
$d=$a+++++$b;
echo$d;
?
>
a)5
b)4
c)3
d)er
ror
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Posti
ncr
ementofai
sdoneaf
terexpr
essi
onev
aluat
ion.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=1;
$b=1;
$d=1;
pr
int++$a+++$a+$a++;
pri
nt$a+++++$b;
pri
nt++$d+$d+++$a++;
?
>
a)869
b)742
c)368
d)er
ror
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Fol
l
owt
heor
derofpostandpr
eincr
ement
s.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=10;
$b=10;
i
f($a=5)
$b-
-;
pr
int$a;
pri
nt$b-
-;
?
>
a)58
b)59
c)109
d)108
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
aissett
o5i
nthei
fcondi
ti
onandbi
spostdecr
ement
edi
nthepr
intst
atement
.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0;
$x=$i
++;
$y=++$i
;
pr
int$x;
pri
nt$y
;
?
>
a)02
b)12
c)01
d)21
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Fir
stcasei
isi
ncr
ement
edaf
terset
ti
ngxt
oi.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=5;
$b=-
7;$c=0;
$d=++$a&&++$b|
|++$c;
pr
int$d;
pri
nt$a;
?
>
a)16
b)06
c)15
d)05
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
1&&0|
|
1isev
aluat
edt
o1andt
heai
sal
sopr
eincr
ement
edt
o6.
11.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$b=1;
$c=4;
$a=5;
$d=$b+$c==$a;
pr
int$d;
?
>
a)5
b)0
c)10
d)1
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Fir
stbandcar
eaddedandt
hent
est
edi
fd=5,
whi
chi
str
uet
husr
etur
n1.
PHPCodi
ngQuest
ionsandAnswer
s–Oper
ator
s–5
Thi
ssetofToughPHPI
nter
viewQuest
ions&Answer
sfocuseson“
Oper
ator
s–5”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0;
$j=1;
$k=2;
pr
int!
((
$i+$k)<(
$j-$k)
);
?
>
a)1
b)t
rue
c)f
alse
d)0
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Truei
s1.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0;
$j=1;
$k=2;
pr
int!
((++$i
+$j
)>(
$j-$k)
);
?
>
a)1
b)noout
put
c)er
ror
d)0
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Theequat
ionout
put
sfal
se.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0;
$j=1;
$k=2;
pr
int(
(++$i
+$j
)>!(
$j-$k)
);
?
>
a)1
b)noout
put
c)er
ror
d)0
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Negat
ionofanumberi
s0.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=0x6db7;
pr
int$a<<6;
?
>
a)1797568
b)noout
put
c)er
ror
d)0x6dc0
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Theout
puti
sindeci
mal
.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a='
a';
pr
int$a*2;
?
>
a)192
b)2
c)er
ror
d)0
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Char
act
erscannotbemul
ti
pli
ed.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a='
4';
pr
int++$a;
?
>
a)noout
put
b)er
ror
c)5
d)0
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Thechar
act
eri
sty
pecast
edt
oint
egerbef
oremul
ti
ply
ing.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a='
12345'
;
pr
int"
qwe{
$a}
rty
";
?
>
a)qwe12345r
ty
b)qwe{
$a}
rty
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
{$}
der
efer
encest
hev
ari
abl
ewi
thi
n.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a='
12345'
;
pr
int"
qwe"
.$a.
"r
ty"
;
?
>
a)qwe12345r
ty
b)qwe$ar
ty
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
.der
efer
encest
hev
ari
abl
e/st
ri
ngwi
thi
n.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a='
12345'
;
echo'
qwe{
$a}
rty
';
?
>
a)qwe12345r
ty
b)qwe{
$a}
rty
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
qwe{
$a}
rty
,si
ngl
equot
esar
enotpar
sed.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a='
12345'
;
echo"
qwe$ar
ty"
;
?
>
a)qwe12345r
ty
b)qwe$ar
ty
c)qwe
d)er
ror
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
qwe,
because$abecame$ar
ty,
whi
chi
sundef
ined.
PHPCodi
ngQuest
ionsandAnswer
s–I
f–El
se–I
f–1
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
If–El
se–I
f–1”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x;
i
f($x)
pr
int"
hi";
el
se
pr
int"
howar
eu"
;
?
>
a)howar
eu
b)hi
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Uni
nit
ial
i
zedxi
ssett
o0,
thusi
fcondi
ti
onf
ail
s.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=0;
i
f($x++)
pr
int"
hi"
;
el
se
pr
int"
howar
eu"
;
?
>
a)hi
b)noout
put
c)er
ror
d)howar
eu
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
xisi
ncr
ement
edaf
teri
fwhi
chev
aluat
est
ofal
se.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x;
i
f($x==0)
pr
int"
hi";
el
se
pr
int"
howar
eu"
;
pr
int"
hel
l
o"
?
>
a)howar
euhel
l
o
b)hi
hel
l
o
c)hi
d)noout
put
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
elsecondi
ti
onwi
thoutbr
acket
sper
for
mst
hef
oll
owi
ngst
atement
sonl
y.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=0;
i
f($x==1)
i
f($x>=0)
pr
int"
tr
ue"
;
el
se
pr
int"
fal
se"
;
?
>
a)t
rue
b)f
alse
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Thenest
edf
orl
oopi
snotent
eredi
fout
ercondi
ti
oni
sfal
se.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=1;
i
f($a-
-)
pr
int"
True"
;
i
f($a++)
pr
int"
Fal
se"
;
?
>
a)t
rue
b)f
alse
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Duet
oposti
ncr
ementandpostdecr
ementonl
ythef
ir
stcondi
ti
oni
ssat
isf
ied.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=1;
i
f(echo$a)
pr
int"
True"
;
el
se
pr
int"
Fal
se"
;
?
>
a)t
rue
b)f
alse
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
echodoesnotr
etur
nany
thi
ngsoi
fcondi
ti
oni
sempt
y.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=1;
i
f(pr
int$a)
pr
int"
True"
;
el
se
pr
int"
Fal
se"
;
?
>
a)t
rue
b)f
alse
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
pri
ntr
etur
ns1i
fitpr
int
sany
thi
ng.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=10;
i
f(1)
pr
int"
all
";
el
se
pr
int"
some"
el
se
pr
int"
none"
;
?
>
a)al
l
b)some
c)er
ror
d)none
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Hangi
ngel
sest
atement
.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=10;
i
f(0)
pr
int"
all
";
i
f
el
se
pr
int"
some"
?
>
a)al
l
b)some
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Noel
sest
atementt
oendt
hei
fst
atement
.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a="
";
i
f($a)
pr
int"
all
";
i
f
el
se
pr
int"
some"
;
?
>
a)al
l
b)some
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Empt
yst
ri
ngi
sev
aluat
edt
o0.
11.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a="
a";
i
f($a)
pr
int"
all
";
el
se
pr
int"
some"
;
?
>
a)al
l
b)some
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Thev
alueofai
sev
aluat
edt
o1asi
thasav
alue.
PHPCodi
ngQuest
ionsandAnswer
s–I
f-
Else-
If
-2
Thi
ssetofPHPQuest
ionBankf
ocuseson”I
f-
Else-
If
-2″
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=10;
$y=20;
i
f($x>$y+$y!
=3)
pr
int"
hi";
el
se
pr
int"
howar
eu"
;
?
>
a)howar
eu
b)hi
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Expr
essi
onev
aluat
est
otr
ue.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=10;
$y=20;
i
f($x>$y&&1|
|
1)
pr
int"
hi";
el
se
pr
int"
howar
eu"
;
?
>
a)howar
eu
b)hi
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Expr
essi
onev
aluat
est
otr
ue.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=10;
$y=20;
i
f($x>$y&&1|
|
1)
pr
int"
hi";
el
se
pr
int"
howar
eu"
;
?
>
a)howar
eu
b)hi
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Expr
essi
onev
aluat
est
otr
ue.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
i
f(-
100)
pr
int"
hi";
el
se
pr
int"
howar
eu"
;
?
>
a)howar
eu
b)hi
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Expr
essi
onev
aluat
est
otr
ue.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
i
f(0.
1)
pr
int"
hi";
el
se
pr
int"
howar
eu"
;
?
>
a)howar
eu
b)hi
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Expr
essi
onev
aluat
est
otr
ue.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
i
f(0.
0)
pr
int"
hi";
el
se
pr
int"
howar
eu"
;
?
>
a)howar
eu
b)hi
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Expr
essi
onev
aluat
est
ofal
se.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
i
f(pr
int"
0")
pr
int"
hi";
el
se
pr
int"
howar
eu"
;
?
>
a)0howar
eu
b)0hi
c)hi
d)howar
eu
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Expr
essi
onev
aluat
est
otr
ueaspr
intr
etur
ns1.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=1;
i
f($x==2)
pr
int"
hi";
el
sei
f(
$x=2)
pr
int$x;
el
se
pr
int"
howar
eu"
;
?
>
a)er
ror
b)2
c)hi
d)howar
eu
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Ent
ersi
fel
seasf
ir
stcondi
ti
oni
sfal
seandt
husxi
ssett
o2.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=1;
i
f($x=$x&0)
pr
int$x;
el
se
pr
int"
howar
eu"
;
?
>
a)0
b)1
c)er
ror
d)howar
eu
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
x&0i
s0,
thusev
aluat
edt
ofal
se.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=1;
i
f($x=$x&0)
pr
int$x;
el
se
pr
int"
howar
eu"
;
?
>
a)0
b)1
c)er
ror
d)howar
eu
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
x&0i
s0,
thusev
aluat
edt
ofal
se.
11.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$x=1;
i
f($x=$x&0)
pr
int$x;
el
se
br
eak;
?
>
a)0
b)1
c)er
ror
d)noout
put
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
breaki
snotdef
inedf
orai
fel
sel
adder
.
12.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$a=100;
i
f($a>10)
pr
int
f("
M.S.Dhoni
")
;
el
sei
f($a>20)
pr
int
f("
M.E.
KHussey
");
el
sei
f(
$a>30)
pr
int
f("
A.B.dev
il
li
ers"
);
?
>
a)M.
S.Dhoni
b)M.
E.K.
Hussey
c)M.
S.Dhoni
M.
E.K.
Hussey
A.
B.dev
il
li
ers
d)Noout
put
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Ini
fel
sei
fonecondi
ti
oni
ssat
isf
iedt
hennoot
hercondi
ti
oni
schecked.
PHPCodi
ngQuest
ionsandAnswer
s–Whi
l
eLoops–1
Thi
ssetofPHPMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Whi
l
eLoops–1”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
whi
l
e()
{
pr
int"
hi"
;
}
?
>
a)i
nfi
nit
eloop
b)hi
c)noout
put
d)er
ror
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Thewhi
l
eloopcannotbedef
inedwi
thoutacondi
ti
on.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
do
{
pr
int"
hi"
;
}
whi
l
e(0)
;
pr
int"
hel
l
o";
?
>
a)i
nfi
nit
eloop
b)hi
hel
l
o
c)hel
l
o
d)er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thedowhi
l
eloopexecut
esatl
eastonceast
hecondi
ti
oni
sint
hewhi
l
eloop.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0
do
{
pr
int"
hi"
;
$i
++;
}
whi
l
e($i
!=3)
;
?
>
a)hi
hi
b)hi
c)hi
hi
hi
hi
d)noout
put
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Thecheckhappensaf
tert
hei
ncr
ement
,t
husi
tpr
int
sunt
ili
=4.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0
whi
l
e($i
!=3)
{
pr
int"
hi"
;
$i
++;
}
?
>
a)hi
hi
b)hi
hi
hi
c)hi
hi
hi
hi
d)noout
put
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thecheckhappensbef
oret
hei
ncr
ement
,thusi
tpr
int
sunt
ili
=3.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0
whi
l
e($i
<3)
{
pr
int"
hi"
;
$i
--
;
}
pr
int"
hel
l
o"
?
>
a)hi
hi
hel
l
o
b)hi
hi
hi
hel
l
o
c)hi
hi
hi
hi
hel
l
o
d)i
nfi
nit
eloop
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Ther
eisnoi
ncr
ementofi
maki
ngi
tinf
ini
te.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0
whi
l
e($i
<3)
{
$i
++;
}
pr
int$i
;
?
>
a)2
b)3
c)0
d)1
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thei
ncr
ementhappensandt
hent
hecheckhappens.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0
do
{
$i
++;
}
whi
l
e($i
<3)
;
pr
int$i
;
?
>
a)2
b)3
c)0
d)1
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Thei
ncr
ementhappensandt
hent
hecheckhappens.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0
whi
l
e($i
++)
{
pr
int$i
;
}
pr
int$i
;
?
>
a)0
b)i
nfi
nit
eloop
c)01
d)1
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Asi
tisaposti
ncr
ement
,itchecksandt
hendoesnotent
ert
hel
oop,
thuspr
int
sonl
y1.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=""
;
whi
l
e($i
)
{
pr
int"
hi"
;
}
pr
int"
hel
l
o";
?
>
a)hel
l
o
b)i
nfi
nit
eloop
c)hi
hel
l
o
d)er
ror
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Whi
l
eacceptdoesnotacceptany
thi
ngot
hert
hana0oranyot
hernumberasf
alseandt
rue.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=""
;
whi
l
e($i
)
{
pr
int"
hi"
;
}
whi
l
e($i
<8)
$i
++;
pr
int"
hel
l
o";
?
>
a)Hi
ispr
int
ed8t
imes,
hel
l
o7t
imesandt
henhi
2ti
mes
b)Hi
ispr
int
ed10t
imes,
hel
l
o7t
imes
c)Hi
ispr
int
edonce,
hel
l
o7t
imes
d)Hi
ispr
int
edonce,
hel
l
o7t
imesandt
henhi
2ti
mes
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Thewhi
l
eloopendsonl
ywhena}i
sencount
ered.
PHPCodi
ngQuest
ionsandAnswer
s–Whi
l
eLoops–2
Thi
ssetofTr
ickyPHPI
nter
viewQuest
ions&Answer
sfocuseson“
Whi
l
eLoops–2”
.
1.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0;
whi
l
e($i
=10)
{
pr
int"
hi"
;
}
pr
int"
hel
l
o";
?
>
a)hel
l
o
b)i
nfi
nit
eloop
c)hi
hel
l
o
d)er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Whi
l
econdi
ti
onal
way
sgi
ves1.
2.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=""
;
whi
l
e($i
=10)
{
pr
int"
hi"
;
}
pr
int"
hel
l
o";
?
>
a)hel
l
o
b)i
nfi
nit
eloop
c)hi
hel
l
o
d)er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Whi
l
econdi
ti
onal
way
sgi
ves1.
3.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=5;
whi
l
e(-
-$i
>0)
{
$i
++;
pri
nt$i
;pr
int"
hel
l
o";
}
?
>
a)4hel
l
o4hel
l
o4hel
l
o4hel
l
o4hel
l
o….
.i
nfi
nit
e
b)5hel
l
o5hel
l
o5hel
l
o5hel
l
o5hel
l
o….
.i
nfi
nit
e
c)noout
put
d)er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
iisdecr
ement
edi
nthewhi
l
eloopi
nthecondi
ti
oncheckandt
heni
ncr
ement
edback.
4.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=5;
whi
l
e(-
-$i
>0&&++$i
)
{
pr
int$i
;
}
?
>
a)5
b)555555555…i
nfi
nit
ely
c)54321
d)er
ror
Vi
ewAnswer
Answer
:b
Expl
anat
ion:
Asi
tis&&oper
atori
tisbei
ngi
ncr
ement
edanddecr
ement
edcont
inuousl
y.
5.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=5;
whi
l
e(-
-$i
>0|
|++$i
)
{
pr
int$i
;
}
?
>
a)54321111111….
inf
ini
tel
y
b)555555555…i
nfi
nit
ely
c)54321
d)5
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Asi
tis|
|oper
atort
hesecondexpr
essi
oni
snotev
aluat
edt
il
libecomes1t
heni
tgoesi
ntoa
l
oop.
6.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0;
whi
l
e(++$i
||-
-$i
)
{
pr
int$i
;
}
?
>
a)1234567891011121314….
i
nfi
nit
ely
b)01234567891011121314…i
nfi
nit
ely
c)1
d)0
Vi
ewAnswer
Answer
:a
Explanat
ion:
Asiti
s||
oper
atort
hesecondexpr
essi
oni
snotev
aluat
edandi
isal
way
sincr
ement
ed,
int
he
fi
rstcaseto1.
adv
ert
isement
7.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0;
whi
l
e(++$i
&&-
-$i
)
{
pr
int$i
;
}
?
>
a)1234567891011121314….
i
nfi
nit
ely
b)01234567891011121314…i
nfi
nit
ely
c)noout
put
d)er
ror
Vi
ewAnswer
Answer
:c
Expl
anat
ion:
Thef
ir
stcondi
ti
oni
tsel
ffai
l
sthust
hel
oopexi
sts.
8.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=0;
whi
l
e((
--
$i>++$i
)-1)
{
pr
int$i
;
}
?
>
a)00000000000000000000….
inf
ini
tel
y
b)-
1-1-
1-1-
1-1-
1-1-
1-1…i
nfi
nit
ely
c)noout
put
d)er
ror
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
(–$i
>++$i
)ev
aluat
est
o0but-
1makesi
tent
erst
hel
oopandpr
int
si.
9.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=2;
whi
l
e(++$i
)
{
whi
l
e($i
-->0)
pr
int$i
;
}
?
>
a)210
b)10
c)noout
put
d)i
nfi
nit
eloop
Vi
ewAnswer
Answer
:a
Expl
anat
ion:
Thel
oopendswheni
becomes0.
10.Whatwi
l
lbet
heout
putoft
hef
oll
owi
ngPHPcode?
<?
php
$i
=2;
whi
l
e(++$i
)
{
whi
l
e(-
-$i
>0)
pr
int$i
;
}
?
>
a)210
b)10
c)noout
put
d)i
nfi
nit
eloop
Vi
ewAnswer
Answer
:d
Expl
anat
ion:
Thel
oopnev
erendsasi
isal
way
sincr
ement
edandt
hendecr
ement
ed.