PHP MCQ Quiz Hub

PHP MCQ

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

1. What is PHP?




2. Who is the father of PHP?




3. What does PHP stand for?




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




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




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




7. How to define a function in PHP?




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




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




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




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




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




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




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




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




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




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




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




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




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




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




22. What does PDO stand for?




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




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




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




26. Which version of PHP introduced the advanced concepts of OOP?




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




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




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




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




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




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




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




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




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




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




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




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




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