PHP MCQ Quiz Hub

PHP Mcq – Functions

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

1. Type Hinting was introduced in which version of PHP?




2. What will be the output of the following PHP code? <?php function calc($price, $tax="") { $total = $price + ($price * $tax); echo "$total"; } calc(42); ?>




3. Which of the following are valid function names? i) function() ii) €() iii) .function() iv) $function()




4. What will be the output of the following PHP code? <?php function a() { function b() { echo 'I am b'; } echo 'I am a'; } a(); a(); ?>




5. What will be the output of the following PHP code? <?php function a() { function b() { echo 'I am b'; } echo 'I am a'; } b(); a(); ?>




6. What will be the output of the following PHP code? <?php $op2 = "blabla"; function foo($op1) { echo $op1; echo $op2; } foo("hello"); ?>




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




8. What will be the output of the following PHP code? <?php function foo($msg) { echo "$msg"; } $var1 = "foo"; $var1("will this wo




9. Which of the following PHP functions accepts any number of parameters?




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




11. Which one of the following functions can be used to compress a string?




12. What will be the output of the following PHP code? <?php echo chr(52); ?>




13. What will be the output of the following PHP code? <?php echo ord ("hi"); ?>




14. What will be the output of the following PHP code? <?php $str = "Hello World"; echo wordwrap($str,5,"<br> "); ?>




15. What will be the output of the following PHP code? <?php echo ucwords("i love my country"); ?>




16. What will be the output of the following PHP code? <?php echo lcfirst("welcome to India"); ?>