Latest PHP Interview Questions & Answer of 2024

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.

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

Categories: php

Blog Categories
Trending Courses

CodeIgniter

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing Expert Course

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 25 Days

Crash : 15 Days

Laravel

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 6 Months

Fastrack : 4 Months

Crash : 2 Months

Python

Regular : 30 Days

Fastrack : 15 Days

Crash : 10 Days

Related Blogs

Request For Demo