R4RIN
Articles
Java 8
MCQS
PHP MCQ Quiz Hub
PHP MCQ
Choose a topic to test your knowledge and improve your PHP skills
1. What is PHP?
PHP is an open-source programming language
PHP is used to develop dynamic and interactive websites
PHP is a server-side scripting language
All of the mentioned
2. Who is the father of PHP?
Drek Kolkevi
Rasmus Lerdorf
Willam Makepiece
List Barely
3. What does PHP stand for?
PHP stands for Preprocessor Home Page
PHP stands for Pretext Hypertext Processor
PHP stands for Hypertext Preprocessor
PHP stands for Personal Hyper Processor
4. Which of the following is the correct syntax to write a PHP code?
<?php ?>
< php >
< ? php ?>
<? ?>
5. Which of the following is the correct way to add a comment in PHP code?
#
//
/* */
All of the mentioned
6. Which of the following is the default file extension of PHP files?
.php
.ph
.xml
.html
7. How to define a function in PHP?
functionName(parameters) {function body}
function {function body}
function functionName(parameters) {function body}
data type functionName(parameters) {function body}
8. What will be the output of the following PHP code? <?php $x = 10; $y = 20; if ($x > $y && 1||1) print "1000 PHP MCQ" ; else print "Welcome to Sanfoundry"; ?>
no output
Welcome to Sanfoundry
1000 PHP MCQ
error
9. Which is the right way of declaring a variable in PHP?
$3hello
$_hello
$_hello
$this
10. What will be the output of the following PHP program? <?php $fruits = array ("apple", "orange", array ("pear", "mango"),"banana"); echo (count($fruits, 1)); ?>
6
5
4
3
11. What will be the output of the following PHP program? <?php function multi($num) { if ($num == 3) echo "I Wonder"; if ($num == 7) echo "Which One"; if ($num == 8) echo "Is The"; if ($num == 19) echo "Correct Answer"; } $can = stripos("I love php, I love php too!","PHP"); multi($can); ?>
Correct Answer
Is The
I Wonder
Which One
12. Which of the following PHP functions can be used for generating unique ids?
md5()
uniqueid()
mdid()
id()
13. . In the following PHP program, what is/are the properties? <?php class Example { public $name; function Sample() { echo "Learn PHP @ Sanfoundry"; } } ?>
function sample()
echo “This is an example”;
public $name;
class Example
14. What will be the output of the following PHP code? <?php define("GREETING", "PHP is a scripting language"); echo $GREETING; ?>
$GREETING
no output
PHP is a scripting language
GREETING
15. A function in PHP which starts with __ (double underscore) is known as __________
Default Function
User Defined Function
Inbuilt Function
Magic Function
16. Which of the following web servers are required to run the PHP script?
Apache and PHP
IIS
XAMPP
Any of the mentioned
17. What will be the output of the following PHP code snippet? <?php $url = "phpmcq@sanfoundry.com"; echo ltrim(strstr($url, "@"),"@"); ?>
phpmcq@sanfoundry.com
php@sanfoundry.com
phpmcq@
sanfoundry.com
18. What will be the output of the following PHP code? <?php $x = 5; $y = 10; function fun() { $y = $GLOBALS['x'] + $GLOBALS['y']; } fun(); echo $y; ?>
5
10
15
Error
19. The developers of PHP deprecated the safe mode feature as of which PHP version?
PHP 5.3.1
PHP 5.3.0
PHP 5.1.0
PHP 5.2.0
20. What will be the value of the variable $input in the following PHP program? <?php $input = "PHP<td>stands for</td>Hypertext<i>Preprocessor</i>!"; $input = strip_tags($input,"<i></i>"); echo $input; ?>
PHP stands for Hypertext &lt;i&gt;Preprocessor&lt;/i&gt;!
PHP stands for Hypertext Preprocessor!
PHP &lt;td&gt;stands for&lt;/td&gt; Hypertext &lt;i&gt;Preprocessor&lt;/i&gt;!
PHP &lt;td&gt;stands for&lt;/td&gt; Hypertext Preprocessor!
21. Which of the following variables does PHP use to authenticate a user? i) $_SERVER['PHP_AUTH_USER']. ii) $_SERVER['PHP_AUTH_USERS']. iii) $_SERVER['PHP_AUTH_PU']. iv) $_SERVER['PHP_AUTH_PW'].
ii) and iv)
i) and iv)
ii) and iii)
i) and ii)
22. What does PDO stand for?
PHP Database Orientation
PHP Data Orientation
PHP Data Object
PHP Database Objec
23. What will be the output of the following PHP program? <?php $a = 100; if ($a > 10) printf("PHP Quiz"); else if ($a > 20) printf("PHP MCQ"); else if($a > 30) printf("PHP Program"); ?>
PHP Quiz PHP MCQ PHP Program
PHP Quiz
PHP MCQ
No output
24. Which of the looping statements is/are supported by PHP? i) for loop ii) while loop iii) do-while loop iv) foreach loop
Only iv)
i) and ii)
i), ii) and iii)
i), ii), iii) and iv)
25. Which PHP statement will give output as $x on the screen?
echo “$x”;
echo “$$x”;
echo “/$x”;
echo “$x;”;
26. Which version of PHP introduced the advanced concepts of OOP?
PHP 6
PHP 4
PHP 5
PHP 5.3
27. What will be the output of the following PHP code? <?php $x = 4; $y = 3 $z = 1; $z = $z + $x + $y; echo "$z"; ?>
15
8
1
$z
28. What will be the output of the following PHP program? <?php $a = "$winner"; $b = "/$looser"; echo $a,$b; ?>
/
$looser
$looser/
$winner/$looser
29. Which one of the following is the default PHP session name?
PHPSESSIONID
PHPIDSESS
PHPSESSID
PHPSESID
30. What will be the output of the following PHP program? <?php $mcq = 1; switch(print $mcq) { case 2: print "HTML"; break; case 1: print "CSS"; break; default: print "JavaScript"; } ?>
error
1HTML
1JavaScript
1CSS
31. What will be the output of the following PHP program? <?php define("VAR_NAME","test"); ${VAR_NAME} = "value"; echo VAR_NAME; echo ${VAR_NAME}; ?>
testtest
testvalue
error, constant value cannot be changed
test
32. Which PHP function displays the web page’s most recent modification date? a)
getlastmod()
get_last_mod()
lastmod()
last_mod()
33. Which PHP function displays the web page’s most recent modification date?
getlastmod()
get_last_mod()
lastmod()
last_mod()
34. What will be the output of the following PHP program? <?php $i = 5; while (--$i > 0 && ++$i) { print $i; } ?>
555555555…infinitely
54321
Error
5
35. What will be the output of the following PHP code? <?php function constant() { define("GREETING", "Welcome to Sanfoundry",true); echo greeting; } ?>
GREETING
Welcome to Sanfoundry
ERROR
greeting
36. Which variable is used to collect form data sent with both the GET and POST methods?
$_BOTH
$REQUEST
$_REQUEST
$BOTH
37. What will be the output of the following PHP program? <?php $php = array("Array", "Function", "Strings", "File"); echo pos($php); ?>
Function
File
Strings
Array
38. What will be the output of the following PHP program? <?php $php = array("Array", "Function", "Strings", "File"); echo pos($php); ?>
Function
File
Strings
Array
39. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?
1
5
12
Error
Submit