# Latest PHP Interview Questions & Answer of 2024

Published: 2024-07-08 · By Next-G Classes · Source: https://nextgclasses.com/blog/latest-php-interview-questions-answer-of-2024

> Next-G Classes is a top institute for IT courses in Delhi NCR. PHP, a powerful server-side scripting language created by Rasmus Lerdorf, simplifies dynamic content creation, database integration, and session management. It ensures robust performance, scalability, and security, making it a preferred choice for developers. Join Next-G Classes to master PHP and elevate your web development career.

<p>PHP, created by Rasmus Lerdorf, is a versatile server-side scripting language renowned for its efficiency in dynamic web content creation, database integration, and session management. Its robust performance and scalability make it a preferred choice for developers worldwide. PHP's open-source nature allows for continuous improvements and community support, ensuring it remains relevant in the ever-evolving web development landscape. Next-G Classes, a leading institute in Delhi NCR, offers comprehensive PHP training, combining expert instruction with practical projects to help you master this powerful language and advance your web development career.<br /><br /></p>
<p>1. What does PHP stand for?<br />i) Personal Home Page<br />ii) Hypertext Preprocessor<br />iii) Pretext Hypertext Processor<br />iv) Preprocessor Home Page<br />A. Both (i) and (ii)<br />B. Both (ii) and (iv)<br />C. Only (ii)<br />D. Both (i) and (iii)<br />Ans.A<br />2. Who is the father of PHP?<br />A. Rasmus Lerdorf<br />B. Willam Makepiece<br />C. Drek Kolkevi<br />D. List Barely<br />Ans.A<br />3. PHP files have a default file extension of.<br />A. .html<br />B. .xml<br />C. .php<br />D. .ph<br />Ans.C<br />4. A PHP script should start with ___ and end with ___:<br /> A.<br /> &lt; php &gt;<br /> B.<br /> &lt; ? php ?&gt;<br /> C.<br /> &lt; ? ? &gt;<br /> D.<br />&lt; ?php ? &gt;<br />Ans.D<br />5. Which of the looping statements is/are supported by PHP?<br />i) for loop<br />ii) while loop<br />iii) do-while loop<br />iv) foreach loop<br />A. (i) and (ii)<br />B. (i), (ii) and (iii)<br />C. All of the mentioned<br />D. None of the mentioned<br />Ans.C<br />6. Which of the following is/are a PHP code editor?<br />i) Notepad<br />ii) Notepad++<br />iii) Adobe Dreamweaver<br />iv) PDT<br />A. Only (iv)<br />B. All of the mentioned.<br />C. (i), (ii) and (iii)<br />D. Only (iii)<br />Ans.B<br />7. Which of the following must be installed on your computer so as to run PHP<br />script?<br />i) Adobe Dreamweaver<br />ii) PHP<br />iii) Apache<br />iv) IIS<br />A. All of the mentioned<br />B. Only (ii)<br />C. (ii) and (iii)<br />D. (ii), (iii) and (iv)<br />Ans.D<br />9. We can use ___ to comment a single line?<br />i) /?<br />ii) //<br />iii) #<br />iv) /* */<br />A. Only (ii)<br />B. (i), (iii) and (iv)<br />C. (ii), (iii) and (iv)<br />D. Both (ii) and (iv)<br />Ans.C<br />10. Which of the below symbols is a newline character?<br />A. \r<br />B. \n<br />C. /n<br />D. /r<br />Ans.B<br />11. Which of the following php statement/statements will store 111 in variable<br />num?<br />i) int $num = 111;<br />ii) int mum = 111;<br />iii) $num = 111;<br />iv) 111 = $num;<br />A. Both (i) and (ii)<br />B. All of the mentioned.<br />C. Only (iii)<br />D. Only (i)<br />Ans.C<br />12. What will be the output of the following php code<br />&lt; ?php<br />$num = 1;<br />$num1 = 2;<br />print $num . "+". $num1 ;<br />?&gt;<br />A. 3<br />B. 1+2<br />C. 1.+.2<br />D. Error<br />Ans.B<br />13. What will be the output of the following php code?<br />&lt; ?php<br />$num = "1";<br />$num1 = "2";<br />print $num+$num1 ;<br />?&gt;<br />A. 3<br />B. 1+2<br />C. Error<br />D. 12<br />Ans.A<br />14. Which of following variables can be assigned a value to it?<br />(i) $3hello<br />(ii) $_hello<br />(iii) $this<br />(iv) $This<br />A. All of the mentioned<br />B. Only (ii)<br />C. (ii), (iii) and (iv)<br />D. (ii) and (iv)<br />Ans.D<br />15. What will be the output of the following code?<br />&lt; ?php<br />$foo = 'Bob';<br />$bar = &amp;$foo;<br />$bar = "My name is $bar";<br />echo $bar;<br />echo $foo;<br />?&gt;<br />A. Error<br />B. My name is BobBob<br />C. My name is BobMy name is Bob<br />D. My name is Bob Bob<br />C<br />16. PHP&rsquo;s numerically indexed array begin with position __.<br />A. 1<br />B. 2<br />C. 0<br />D. -1<br />Ans.C<br />17. Which of the functions is used to sort an array in descending order?<br />A. sort()<br />B. asort()<br />C. rsort()<br />D. dsort()<br />Ans.C<br />18. Which of the following are correct ways of creating an array?<br />(i) state[0] = &ldquo;karnataka&rdquo;;<br />(ii) $state[] = array(&ldquo;karnataka&rdquo;);<br />(iii) $state[0] = &ldquo;karnataka&rdquo;;<br />(iv) $state = array(&ldquo;karnataka&rdquo;);<br />A. (iii) and (iv)<br />B. (ii) and (iii)<br />C. Only (i)<br />D. (ii), (iii) and (iv)<br />Ans.A<br />19. What will be the output of the following PHP code?<br />&lt; ?php<br /> $fruits = array ("mango", "apple", "pear", "peach");<br /> $fruits = array_flip($fruits);<br /> echo ($fruits[0]);<br />?&gt;<br />A. mango<br />B. Error<br />C. peach<br />D. 0<br />Ans.B<br />20. What will be the output of the following php code?<br />&lt; ?php<br /> $states = array("karnataka" =&gt; array<br /> ( "population" =&gt; "11,35,000", "captial" =&gt; "Bangalore"),<br /> "Tamil Nadu" =&gt; array( "population" =&gt; "17,90,000",<br /> "captial" =&gt; "Chennai") );<br /> echo $states["karnataka"]["population"];<br />?&gt;<br />A. karnataka 11,35,000<br />B. 11,35,000<br />C. population 11,35,000<br />D. karnataka population<br />Ans.B<br />21. Which function can be used to move the pointer to the previous array<br />position?<br />A. last()<br />B. before()<br />C. prev()<br />D. previous()<br />Ans.C<br />22. PHP is _____________ scripting Language?<br />A. Server side B. Client side<br />C. Middle side D. None of above<br />Ans. A<br />23. PHP script is executed on?<br />A. ISP Computer B. Server computer<br />C. Client computer D. None of above<br />Ans. B<br />Which of the following variables is not a predefined variable?<br />A.$get B.$ask<br />C.$request D.$post<br />Ans. B<br />24) When you need to obtain the ASCII value of a character<br />which of the following function you apply in PHP?<br />A.chr( ); B.asc( );<br />C.ord( ); D.val( );<br />Ans. C<br />25) Which of the following method sends input to a script via a<br />URL?<br />A.Get B.Post<br />C.Both D.None<br />Answer : Option A<br />26) Which of the following function returns a text in title case<br />from a variable?<br />A.ucwords($var) B.upper($var)<br />C.toupper($var) D.ucword($var)<br />Answer : Option A<br />27) Which of the following function returns the number of<br />characters in a string variable?<br />A.count($variable) B.len($variable)<br />C.strcount($variable) D.strlen($variable)<br />Answer : Option D<br />28) Which of the following are not considered as Boolean false?<br />a. FALSE b. 0<br />c. &ldquo;0&rdquo; d. &ldquo;FALSE&rdquo;<br />e. 1 f. NULL<br />Ans: d and e<br />29) What is the output of the following code?<br />a. Array ([x]=&gt;9 [y]=&gt;3 [z]=&gt;-7)<br />b. Array ([x]=&gt;3 [y]=&gt;2 [z]=&gt;5)<br />c. Array ([x]=&gt;12 [y]=&gt;5 [z]=&gt;-2)<br />d. Error<br />e. None of the above<br />Ans: c<br />30) Which of the following multithreaded servers allow PHP as a plug-in?<br />a. Netscape FastTrack<br />b. Microsoft&rsquo;s Internet Information Server<br />c. O&rsquo;Reilly&rsquo;s WebSite Pro<br />d. All of the above<br />Ans: d<br />31) Which of the following type cast is not correct?<br />a. real<br />b. double<br />c. decimal<br />d. boolean<br />Ans: c<br />32) which of the following are the valid PHP data types?<br />a. resource<br />b. null<br />c. boolean<br />d). All of the above<br />Ans: d<br />33) which of the following characters are taken care of by htmlspecialchars?<br />a. &lt; b. &gt;<br />c. single quote<br />d. double quote<br />e. &amp;<br />f. All of the above<br />Ans: f<br />34) which of the following is a correct declaration?<br />a. static $varb = array(1,&rsquo;val&rsquo;,3);<br />b. static $varb = 1+(2*90);<br />c. static $varb = sqrt(81);<br />d. static $varb = new Object;<br />Ans: a<br />35) Which of the following is Ternary Operator?<br />a. &amp;<br />b. =<br />c. ?:<br />e. +=<br />Ans: c<br />36) which of the following pair have non-associative equal precedence?<br />a. +,-<br />b. ==, !=<br />c.+, /<br />d. &amp;=, |=<br />Ans: b<br />37) Which of the following functions output text?<br />a. echo()<br />b. print()<br />c. both a,b<br />d. display()<br />Ans: c<br />38) Which of the following statement is not correct for PHP?<br />a. It is a server side scripting language<br />b. A PHP file may contain text, html tags or scripts<br />c. It can run on windows and Linux systems only<br />d. It is compatible with most of the common servers used today<br />Ans: c<br />39) Which of the following printing construct/function accepts multiple<br />parameters?<br />a. echo<br />b. print<br />c. printf<br />d. All of the above<br />Ans: a<br />40) What will be the output of the following code?<br />$a = 10;<br />if ($a &gt; 5 OR &lt; 15)<br />echo &lsquo;true&rsquo;;<br />else<br />echo &lsquo;false&rsquo;;<br />a. true<br />b. false<br />c. No output<br />d. Parse Error<br />Ans: d<br />41) Which of the following variable names are invalid?<br />a. $var_1<br />b. $var1<br />c. $var-1<br />d. $var/1<br />e. Both c,d<br />Ans: e<br />42) What will be the output of following code?<br />$a = 10;<br />echo &lsquo;Value of a = $a&rsquo;;<br />a. Value of a = 10<br />b. Value of a = $a<br />c. Undefined<br />d. Syntax Error<br />Ans: a<br />43) What will be the output of the following code?<br />$Rent = 250;<br />function Expenses($Other)<br />{<br />$Rent = 250 + $Other;<br />return $Rent;<br />}<br />Expenses(50);<br />echo $Rent;<br />a. 300<br />b. 250<br />c. 200<br />d. Program will not compile<br />Ans: b<br />45) The following php variables are declared:<br />$company = &lsquo;ABS Ltd&rsquo;;<br />$$company = &lsquo;,Sydney&rsquo;;<br />Which of the following is not a correct way of printing &lsquo;ABS Ltd,Sydney&rsquo;?<br />a. echo &lsquo;$company $$company&rsquo;;<br />b. echo &lsquo;$company ${$company}&rsquo;;<br />c. echo &lsquo;$company ${&lsquo;ABS Ltd&rsquo;}&rsquo;;<br />d. echo &lsquo;$company {$$company}&rsquo;;<br />Ans: a<br />46) Which of the following is not supported in PHP5?<br />a. Type Hinting<br />b. Reflection<br />c. Magic Methods<br />d. Multiple Inheritance<br />Ans: d<br />47) Which of the following is correct with regard to echo and print?<br />a. echo is a construct and print is a function<br />b. echo is a function and print is a construct<br />c. Both are functions<br />d. Both are constructs<br />Ans: d<br />48) What will be the output of following code?<br />$a = 10;<br />echo &lsquo;Value of a = $a&rsquo;;<br />a. Value of a = 10<br />b. Value of a = $a<br />c. Undefined<br />d. Syntax Error<br />Ans: a<br />49) Which of the following is a PHP resource?<br />a. Domxml document<br />b. Odbc link<br />c. File<br />d. All of the above<br />Ans: d<br />50) In multidimensional arrays rather than a single key they values are stored in<br />A. Sequence of key values<br />B. 2 keys<br />C. linear style<br />D. None of them<br />Ans.A</p>
