PHP Questions and Answers – Functions – Part 2
This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “PHP Functions”.
1. Which the following declaration are valid function names?
A .function()
B function()
C $function()
D €()
2. Which PHP functions that begins with double underscore __________.
A Inbuilt Function
B Magic Function
C Default Function
D User Defined Function
3. What is the result of the following PHP code?
<?php function a() { function b() { echo 'B'; } echo 'A'; } b(); a(); ?>
A BA
B AB
C BBA
D Error
4. Which the following are the mathematical functions in PHP?
A pow
B exp
C log
D log5()
5. Writing 2**4; will return the following result in PHP
A 2
B 4
C 8
D 16
6. What is the result of the following PHP code?
<?php $foo = "ipsum"; function fun($bar) { echo $bar; echo $foo; } fun("lorem"); ?>
A loremipsum
B lorem
C ipsum
D Error
7. What is the result of the following PHP code?
<?php function show($msg) { echo "$msg"; } $display = "show"; $display("Welcome To StackHowTo!"); ?>
A $msg
B show
C Welcome To StackHowTo!
D Error
8. What is the result of the following PHP code?
<?php function prod($n1, $n2, $n3) { $res = $n1 * $n2 * $n3; echo "The product is $res"; } prod(1, 2, 3, 4); ?>
A The product is 24
B The product is 12
C The product is 6
D Error
9. Which function in PHP allow you to convert a string to an array?
A explode()
B to_array()
C implode()
D expand()
10. What is the result of the following PHP code?
<?php $str = "HELLO"; $str = lcfirst($str); echo $str; ?>
A HELLO
B hello
C Hello
D hELLO