《PHP面试题附答案.docx》由会员分享,可在线阅读,更多相关《PHP面试题附答案.docx(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、PHP面试题附答案1.Whichofthefollowingwillnotaddjohntotheusersarray?1.$users=john2.array_add($users,john);3.array_push($users,john);4.$users|=johnAnswer:2,42.Whatsthedifferencebetweensort(),asort()andksort(),rsort()?Underwhatcircumstanceswouldyouuseeachofthese?sort():本函数对数组的值进行排序。当本函数结束时数组单元将被从最低到最高重新安排,arr
2、ay中的单元赋予新的键名。这将删除原有的键名而不仅是重新排序。asort():这个函数将数组的值重新排序,由小至大排列。数组的索引亦跟着值的顺序而变动。当您在程序中需要重新整理数组值的顺序时,就能够使用这个函数。ksort():对数组根据键名排序,保留键名到数据的关联。本函数主要用于关联数组。rsort():本函数对数组进行逆向排序(最高到最低)。与sort()执行相反的操作。3.Whatwouldthefollowingcodeprinttothebrowser?Why?$num=10;functionmultiply()$num=$num*10;multiply();echo$num;10
3、4.Whatisthedifferencebetweenareferenceandaregularvariable?Howdoyoupassbyreferencewhywouldyouwantto?passbyreferencelikethisfunctions($vars);itlikesmorefast;5.Whatfunctionscanyouusetoaddlibrarycodetothecurrentlyrunningscript?inlcude()orrequire();6.Whatisthedifferencebetweenfoo()foo()?iffoo()throwaerro
4、r,willbealert,butfoo()no;7.HowdoyoudebugaPHPapplication?xdebugorusedie()doit;8.Whatdoes=do?Whatsanexleofsomethingthatwillgivetruefor=,butnot=?=用于准确比拟ex:(=null)=truebut(=null)=false;9.Howwouldyoudeclareaclassnamedmyclasswithnomethodsorproperties?classmyclass10.Howwouldyoucreateanobject,whichisaninsta
5、nceofmyclass?$myoject=newmyclass();11.Howdoyouaccessandsetpropertiesofaclassfromwithintheclass?getVar()orsetVar();12.Whatisthedifferencebetweenincludeinclude_once?includerequire?require:PHP程式在执行前,就会先读入require所指定引入的档案,使它变成PHP程式网页的一部份。常用的函式,亦能够这个方法将它引入网页中。错误产生致命错误。include:这个函式一般是放在流程控制的处理区段中。PHP程式网页在读
6、到include的档案时,才将它读进来。这种方式,能够把程式执行时的流程简单化。错误产生警报。include_once:此行为和include()语句类似,唯一区别是假如该文件中的代码已经被包含了,则不会再次包含。好像此语句名字暗示的那样,只会包含一次。13.Whatfunctionwouldyouusetoredirectthebrowsertoanewpage?1.redir()2.header()3.location()4.redirect()214.Whatfunctioncanyouusetoopenafileforreadingandwriting?1.fget();2.file_
7、open();3.fopen();4.open_file();315.Whatsthedifferencebetweenmysql_fetch_row()andmysql_fetch_array()?mysql_fetch_row():返回根据所获得的行生成的数组,假如没有更多行则返回FALSE。mysql_fetch_array():是mysq_fetch_row()的扩展版本。除了将数据以数字索引方式储存在数组中之外,还能够将数据作为关联索引储存,用字段名作为键名。16.Whatdoesthefollowingcodedo?Explainwhatsgoingonthere.$date=08
8、/26/2003printereg_replace(0-9+)/(0-9+)/(0-9+),2/1/3,$date);本函数以正则的规则来解析比对字符串,欲取而代之的字符串为2/1/3。返回值为字符串类型,为取代后的字符串结果。17.Givenalineoftext$string,howwouldyouwritearegularexpressiontostripallthetagsfromit?strip_tags18.WhatsthedifferencebetweenthewayPHPandPerldistinguishbetweenarraysandhashes?19.HowcanyougetroundthestatelessnatureofHTTPusingPHP?20.WhatdoestheGDlibrarydo?21.Nameafewwaystooutput(print)ablockofcodeinPHP?22.IsPHPbetterthanPerl?Discuss.假如成功则返回TRUE,失败则返回FALSE。【PHP面试题附答案】