Php Functions(Engineering > Computer Science And Engineering > Php ) Questions and Answers
Question 1. Which one of the following is the right way of defining a function in PHP?
function fumctionName(parameters) { function body }
function { function body }
functionName(parameters) { function body }
data type functionName(parameters) { function body }
Explanation:-
Answer: Option A. -> function fumctionName(parameters) { function body }
Question 2. What will be the output of the following PHP code?function calc($price, $tax="") {$total = $price + ($price * $tax);echo "$total";}calc(42);
0
42
Error
84
Explanation:-
Answer: Option B. -> 42
Question 3. What will happen in this function call?function calc($price, $tax) {$total = $price + $tax;}$pricetag = 15;$taxtag = 3;calc($pricetag, $taxtag);
Default Argument Value
Call By Value
Call By Reference
Type Hinting
Explanation:-
Answer: Option B. -> Call By Value
Question 4. Type Hinting was introduced in which version of PHP?
PHP 4
PHP 5
PHP 5.3
PHP 6
Explanation:-
Answer: Option B. -> PHP 5
Question 5. Which of the following are valid function names?1. function()2. €()3. .function()4. $function()
None of the mentioned
3 and 4
All of the mentioned
Only 2
Explanation:-
Answer: Option D. -> Only 2
Question 6. What will be the output of the following PHP code?function a() {function b() {echo 'I am b';}echo 'I am a';}a();a();
I am bI am a
I am b
I am a Error
Error
Explanation:-
Answer: Option C. -> I am a Error
Question 7. What will be the output of the following PHP code?$op2 = "blabla"; function foo($op1) {echo $op1;echo $op2;}foo("hello");
helloblabla
helloblablablabla
Error
hello
Explanation:-
Answer: Option D. -> hello
Question 8. What will be the output of the following PHP code?function a() {function b() {echo 'I am bb';}echo 'I am a';}b();a();
I am a Error
I am bI am a
I am bb
Error
Explanation:-
Answer: Option D. -> Error
Question 9. What will be the output of the following PHP code?function foo($msg) {echo "$msg";}$var1 = "foo";$var1("will this work");
Error
Will this work
0
$msg
Explanation:-
Answer: Option B. -> Will this work
Question 10. A function in PHP which starts with ______ (double underscore) is know as.