测试您的 PHP 水平的题目
2018-09-07 12:14
在UnixReview上看到这个很有意思的测试,和大家共享。
May2007
TestYourKnowledgeofPHP
byEmmettDulaney
From:
Increasingly,PHPseemstobethetool/languagethatisusedtomakeWebsitesdynamic.Whileitisfarfromtheonlyopensourcescriptinglanguageavailable,PHPsabilitiesandfeaturesarequicklymakingitnotonlyamust-haveintheWebworldbutalsoatopiconmanycertificationexams.FollowingarefiftyquestionsonPHPattheknowledgelevelfoundonbeginning/intermediatecertificationexams.Goodluck(answersareattheendofthearticle)!
1.WhatistheclosingtagusedbyaPHP-drivenwebpage?
A./>
B.#>
C.?>
D..>
2.WhichPHPconditionaloperatormeansthevaluesareequalANDofthesamedatatype?
A.==
B.
C.===
D.==?
3.WhichofthefollowingstatementsistrueregardingvariablesinPHP(choosetwo)?
A.VariablenamesinPHParecasesensitive.
B.VariablenamesinPHParenotcasesensitive.
C.PHPvariablesneedtobedeclaredbeforetheycanbeused.
D.PHPvariablesdonotneedtobedeclaredbeforetheycanbeused.
4.Youareevaluatingascriptwrittenbyapreviousemployee.Thatscriptcontainsarequirestatementthatcausesthescripttoexitwhenanerroroccurs.Youwanttochangethissothescriptwillgenerateawarningwhensuchanerroroccurs,butkeeponrunning.Whatshouldyoureplacerequirewith?
A.involve
B.need
C.include
D.call_for
5.WhichofthefollowingdoesnotrepresentacommentinaPHPscript?
A.//Thisisacomment
B.<?commentThisisacomment/>
C.#Thisisacomment
D./*Thisisacomment*/
6.WhichescapecharacterinPHPrendersalinefeed?
A.\n
B.\r
C.\t
D.\\
7.WhatfileisusedtoconfigureglobalPHPsettings?______________(Fillintheblank.)
8.Ifthevalueof$AUiscurrently7,whatisitsvalueasaresultofthecommand$AU++;
A.8
B.9
C.14
D.49
9.Whichprintftypespecifierisusedforafloatingpointvalue?
A.d
B.f
C.s
D.u
10.WhichPHPlogicaloperatorisusedtoseeifbothaandbaretrue?
A.a&b
B.a&&b
C.ab
D.ab
11.Ifanarrayholds100entries,whichidentifiersignifiesthefirstentry?
A.100
B.99
C.1
D.0
12.Whatfunctionmustbecalledtosendtherandomnumbergeneratorbeforearray_rand()?
A.limit()
B.scope()
C.srand()
D.hinum()
13.Whichtwochoicesbelowrepresentthedefaultorderresultingfromasortutilizingasort()?
A.A-Z
B.Z-A
C.0-9
D.9-0
14.Whichofthefollowingisnottrueforvariablenames?
A.Theycancontainanunderscorecharacter
B.Theycanbeginwithanumericcharacter
C.Theycanbeginwithanalphacharacter
D.Theycancontainalphanumericcharacters
15.WhatistheopeningtagusedonaPHP-drivenwebpage?
A.<?php
B.<php
C.</php
D.<P
16.Whatareusedtoseparateblocksofstatementswithinacontrolstructure?
A.brackets[]
B.parentheses()
C.curlybraces{}
D.quotationmarks
17.Whichfunctioncanbeusedtoassignadatatypetoavariable?
A.assign
B.assigntype
C.settype
D.type
18.WhichHTTPvariablecontainstheIPaddressofthemachinemakingarequest?
A.ADDR_IP
B.ADDR
C.IP_ADDR
D.REMOTE_ADDR
19.Youarecreatingasimpleformforwebuserstosendyouamessage.Whichmethodshouldbeusedwiththatform?
A.POST
B.GET
C.SEND
D.READ
20.WithinyourPHPscript,youareperformingadivisionoperationontwovariables.Whatdatatypeisassignedtothedivisionresult,bydefault,ifitisafractionalresult?
A.integer
B.double
C.string
D.Boolean
21.Whichmodeofthefopen()functionopensafileforreadingorwriting,maintainsexitingcontent,andplacesthefilepointeratthebeginningofthefile?
A.w
B.a
C.r+
D.w+
22.Whichfunctioncanbeusedtocopyafile?
A.copy()
B.clone()
C.rename()
D.repr()
23.Whichofthefollowingisusedtosetacookietoexpire24hoursfromnow?
A.$cookie_expire=time()+24
B.$cookie_expire=time()+1440
C.$cookie_expire=time()+86400
24.WhichcharacterisusedasastatementterminatortoindicatetheendofaPHPcommand?
A.=
B.#
C.
D.;
25.Whichofthefollowingcommandswillinitializethe$daysarray?
A.$days=()
B.$days=array();
C.$days=
D.$days=initialize[]
E.12345
F.12,3,45
G.1{2,3,4}5
26.Whatfunctioncanbeusedtoseeifafileexists?
A.file()
B.file_there()
C.exist_file()
D.file_exists()
27.Tocreateacookie,yourcodeusesthefollowingentry:SetCookie(user,EmmettDulaney,time()+1800);WhichofthefollowingisthebesttousetoseethevalueEmmettDulaney?
A.$user
B.$COOKIE[user]
C.$_COOKIE[user]
D.$COOKIE_user
28.Whichofthefollowingshouldbeusedtocombinetwoormoreexistingarrays?
A.array_add()
B.array_merge()
C.array_join()
D.array_combine()
29.Whatfunctionisusedtodeterminewhetherasessionhasbeenstartedforthecurrentuserandthenstartoneifnecessary?__________(Fillintheblank.)
30.Afteropeningafilewiththefopen()function,whatisusedtoclosethefilepointer?
A.fclose()
B.close()
C.die()
D.end()
31.Whichofthefollowingfunctionscanbeusedtoshowthedatatypeforthe$remainvariable?
A.echoshow($remain);
B.echogettype($remain);
C.echotype($remain);
D.echoexplain($remain);
32.Whichofthefollowingfunctionsremovesadirectoryfromafilesystem?
A.rmdir()
B.dir()
C.del()
D.dir_gone()
33.Whatisthedifferencebetweensleep()andusleep()?
A.sleep()suspendsoperationsandusleep()resumesthem
B.sleep()acceptssecondsandusleep()acceptsmilliseconds
C.sleep()worksforthecurrentprocessandusleep()worksforallprocesses
D.sleep()canonlybespecifiedforthecurrentuserandusleep()canbespecifiedforallusers
34.Youneedtoknowhowmanyelementsareinanarray.Whatfunctionshouldyouusetocountthis?
A.list()
B.count()
C.number()
D.sizeof()
35.Informationaboutasession,bydefault,isconfiguredinthePHPconfigurationfiletobesavedbeneathwhichdirectory?
A./var
B./etc
C./tmp
D./usr
36.Whichofthefollowingcontainsvariablesprovidedtoascriptbymeansoftheserverenvironment?
A.$_FILES
B.$_POST
C.$_GET
D.$_ENV
37.Whichofthefollowingcanbeusedtodeleteafile?
A.delete()
B.rid()
C.unlink()
D.close()
38.Whichofthefollowingfunctionscanbeusedtodestroyavariable?
A.erase
B.fi
C.remove
D.unset
39.Whichmodeofthefopen()functionopensafileforwritingandplacesthefilepointerattheendofthefile?
A.w
B.a
C.r+
D.w+
40.WhichHTTPvariablecontainsthebrowsertype,andbrowserversion,amongothervalues?
A.BROWSE_AGENT
B.BROWSER_TYPE
C.BROWSER_ENV
D.HTTP_USER_AGENT
41.Ifthecurrentvalueof$bsnsis4400,whatisthenewvalueasaresultofthiscommand:$bsns-=150;
A.-150
B.150
C.4250
D.4400
E.4550
F.4400-150
42.Whatareusedtoencloseconditionalexpressions?
A.brackets[]
B.parentheses()
C.curlybraces{}
D.quotationmarks
43.WhichPHPdatatypecanbeeitherTRUEorFALSE?
A.Truth
B.Integer
C.Boolean
D.Float
44.Whichofthefollowingcontainsvariablesprovidedtoascriptbymeansoffileuploads?
A.$_FILES
B.$_POST
C.$_GET
D.$_ENV
45.Whichconstantidentifiesthehighestrandomnumberthatthesystemcangenerate?
A.URAND
B.END_NUMBER
C.ULIMIT
D.RAND_MAX
46.PHPprovidessupportforPOSIXthroughfunctionsofwhichclass?
A.grep
B.ereg
C.psx
D.efgrp
47.FromaBooleanstandpoint,everyzerovalueinPHPisconsidered:
A.True
B.False
C.Error
D.Null
48.Whichfunctionplacesresultsintheoppositeorderofasort()?
A.arsort()
B.rev()
C.trosa()
D.zsort()
49.Whichprintftypespecifierisusedforastring?
A.d
B.f
C.s
D.u
50.WhichPHPconditionaloperatormeansnotequalto?
A.!=
B.=!
C.<=>
D.<>
Answers
1.TheclosingtagusedbyPHPis?>.Answer:C.
2.ThePHPconditionaloperatorofthreeequalsigns(===)meansthevaluesareequalandofthesamedatatype.Answer:C.
3.PHPvariablenamesarecasesensitiveandvariablesdonotneedtobedeclaredbeforetheycanbeused.Answer:AandD.
4.Theincludeinstructionwillcreateawarning,butallowthescripttocontinuerunningwhenanerrorisencountered.Answer:C.
5.ThereareatleastthreewaystocreatecommentsinaPHPscript,and<commentisnotoneofthem.Answer:B.
6.The\nescapecharacterinPHPrendersalinefeed.Answer:A.
8.Thecommand$AU++;incrementsthevariablebyone–changingitfrom7to8.Answer:A.
9.Theprintftypespecifierfisusedforafloatingpointvalue.Answer:B.
10.ThePHPlogicaloperatortousetoseeifbothaandbaretruewouldbea&&b.Answer:B.
11.Thefirstentryis0,thesecondis1,andthenumbersincrementfromthere.Answer:D.
12.Thesrand()functionmustbecalledtosendtherandomnumbergeneratorbeforearray_rand().Answer:C.
13.Thedefaultorderresultingfromasortutilizingasort()isalphabetic(A-Z)andlowesttohighest(0-9).Answer:AandC.
14.Variablenamescannotbeginwithanumericcharacter.Answer:B.
15.TheopeningtagusedbyPHPis<?php.Answer:A.
16.Curlybracesareusedtoseparateblocksofstatementswithinacontrolstructure.Answer:C.
17.Thesettypefunctioncanbeusedtoassignadatatypetoavariable.Answer:C.
18.TheREMOTE_ADDRHTTPvariablecontainstheIPaddressofthemachinemakingarequest.Answer:D.
19.ThePOSTmethodshouldbeusedforaformasdescribed.Answer:A.
20.Iftheresultisnotawholenumber,itisassignedthedoubledatatypeIfitisawholenumber,integerisassigned.Answer:B.
21.Ther+modeofthefopen()functionopensafileforreadingorwriting,maintainsexitingcontent,andplacesthefilepointeratthebeginningofthefile.Answer:C.
22.Thecopy()functioncanbeusedtocopyafile.Answer:A.
23.Tosetacookietoexpire24hoursfromnow,computethenumberofsecondsandusethetime()function:$cookie_expire=time()+86400.Answer:C.
24.Thesemicoloncharacter(;)isusedasastatementterminatortoindicatetheendofaPHPcommand.Answer:D.
25.Thecommand$days=array();willinitializethe$daysarray.Answer:B.
26.Thefile_exists()functioncanbeusedtoseeifafilebythegivennameisalreadyinexistence.Answer:D.
27.Thevalueof$_COOKIE[user]isequaltowhatwassetinthecookie.Answer:C.
28.Thearray_merge()functionshouldbeusedtocombinetwoormoreexistingarrays.Answer:B.
29.Thefunctiontouseissession_start()
30.Afteropeningafilewiththefopen()function,fclose()isusedtoclosethefilepointer.Answer:A.
31.Thegettypefunctioncanbeusedtoshowthedatatypeforavariable.Answer:B.
32.Thermdir()functionremovesadirectoryfromafilesystem.Answer:A.
33.sleep()acceptssecondsandusleep()acceptsmilliseconds.Answer:B.
34.Thesizeof()functioncantellhowmanyelementsareinanarrayAnswer:D.
35.Informationaboutasession,bydefault,isconfiguredinthePHPconfigurationfiletobesavedbeneath/tmp.Answer:C.
36.$_ENVcontainsvariablesprovidedtoascriptbymeansoftheserverenvironment.Answer:D.
37.Theunlink()functioncanbeusedtodeleteafile.Answer:C.
38.Theunsetfunctioncanbeusedtodestroyavariable.Answer:D.
39.Theamodeofthefopen()functionopensafileforwritingandplacesthefilepointerattheendofthefile.Answer:B.
40.TheHTTP_USER_AGENTHTTPvariablecontainsthebrowsertype,andbrowserversion,amongothervalues.Answer:D.
41.Thisoperationsubtracts150fromtheexistingvalue.Answer:C.
42.Parenthesesareusedtoencloseconditionalexpressions.Answer:B.
43.TheBooleanPHPdatatypecanbeeitherTRUEorFALSE.Answer:C.
44.$_FILEScontainsvariablesprovidedtoascriptbymeansoffileuploads.Answer:A.
45.TheRAND_MAXconstantidentifiesthehighestrandomnumberthatasystemcangenerate.Answer:D.
46.PHPprovidessupportforPOSIXthroughfunctionsoftheeregclass.Answer:B.
47.FromaBooleanstandpoint,everyzerovalueinPHPisconsideredfalse.Answer:B.
48.Thearsort()functionplacesresultsintheoppositeorderofasort().Answer:A.
49.Theprintftypespecifiersisusedforastring.Answer:C.
50.The!=PHPconditionaloperatormeansnotequalto.Answer:A.