PHP MCQ Quiz Hub

PHP MCQ

Choose a topic to test your knowledge and improve your PHP skills

What is PHP?





✅ Correct Answer: 4

Who is the father of PHP?





✅ Correct Answer: 2

What does PHP stand for?





✅ Correct Answer: 3

Which of the following is the correct syntax to write a PHP code?





✅ Correct Answer: 4

Which of the following is the correct way to add a comment in PHP code?





✅ Correct Answer: 4

Which of the following is the default file extension of PHP files?





✅ Correct Answer: 1

How to define a function in PHP?





✅ Correct Answer: 3

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"; ?>





✅ Correct Answer: 3

Which is the right way of declaring a variable in PHP?





✅ Correct Answer: 2

What will be the output of the following PHP program? <?php $fruits = array ("apple", "orange", array ("pear", "mango"),"banana"); echo (count($fruits, 1)); ?>





✅ Correct Answer: 1

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: 4

Which of the following PHP functions can be used for generating unique ids?





✅ Correct Answer: 2

. In the following PHP program, what is/are the properties? <?php class Example { public $name; function Sample() { echo "Learn PHP @ Sanfoundry"; } } ?>





✅ Correct Answer: 3

What will be the output of the following PHP code? <?php define("GREETING", "PHP is a scripting language"); echo $GREETING; ?>





✅ Correct Answer: 2

A function in PHP which starts with __ (double underscore) is known as __________





✅ Correct Answer: 4

Which of the following web servers are required to run the PHP script?





✅ Correct Answer: 2

What will be the output of the following PHP code snippet? <?php $url = "phpmcq@sanfoundry.com"; echo ltrim(strstr($url, "@"),"@"); ?>





✅ Correct Answer: 4

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; ?>





✅ Correct Answer: 2

The developers of PHP deprecated the safe mode feature as of which PHP version?





✅ Correct Answer: 2

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; ?>





✅ Correct Answer: 1

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'].





✅ Correct Answer: 2

What does PDO stand for?





✅ Correct Answer: 3

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"); ?>





✅ Correct Answer: 2

Which of the looping statements is/are supported by PHP? i) for loop ii) while loop iii) do-while loop iv) foreach loop





✅ Correct Answer: 4

Which PHP statement will give output as $x on the screen?





✅ Correct Answer: 1

Which version of PHP introduced the advanced concepts of OOP?





✅ Correct Answer: 3

What will be the output of the following PHP code? <?php $x = 4; $y = 3 $z = 1; $z = $z + $x + $y; echo "$z"; ?>





✅ Correct Answer: 2

What will be the output of the following PHP program? <?php $a = "$winner"; $b = "/$looser"; echo $a,$b; ?>





✅ Correct Answer: 1

Which one of the following is the default PHP session name?





✅ Correct Answer: 3

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"; } ?>





✅ Correct Answer: 4

What will be the output of the following PHP program? <?php define("VAR_NAME","test"); ${VAR_NAME} = "value"; echo VAR_NAME; echo ${VAR_NAME}; ?>





✅ Correct Answer: 2

Which PHP function displays the web page’s most recent modification date? a)





✅ Correct Answer: 1

Which PHP function displays the web page’s most recent modification date?





✅ Correct Answer: 1

What will be the output of the following PHP program? <?php $i = 5; while (--$i > 0 && ++$i) { print $i; } ?>





✅ Correct Answer: 1

What will be the output of the following PHP code? <?php function constant() { define("GREETING", "Welcome to Sanfoundry",true); echo greeting; } ?>





✅ Correct Answer: 2

Which variable is used to collect form data sent with both the GET and POST methods?





✅ Correct Answer: 3

What will be the output of the following PHP program? <?php $php = array("Array", "Function", "Strings", "File"); echo pos($php); ?>





✅ Correct Answer: 4

What will be the output of the following PHP program? <?php $php = array("Array", "Function", "Strings", "File"); echo pos($php); ?>





✅ Correct Answer: 4

If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?





✅ Correct Answer: 2