Functions - Study Mode
[#21] What will be the output of the following PHP code ? <?php function test ( $int ) { if ( $int == 1 ) echo "This Works"
if ( $int == 2 ) echo "This Too Seems To Work"
} test ( 1 )
TEST ( 2 )
?>
Correct Answer
(C) This WorksThis Too Seems To Work
Explanation
Solution: Function Is case Insensitive.
[#22] What will be the output of the following PHP code ? <?php function mine ( $num ) { $num = 2 + $num
echo $num
} mine ( 3 )
?>
Correct Answer
(C) 5
Explanation
Solution: Simple arithmetic operation.
[#23] What will be the output of the following PHP code ? <?php function mine ( $num ) { $num = 2 + $num
echo "$num"
} mine ( 3 )
?>
Correct Answer
(B) $num
Explanation
Solution: The function is defined as echo “$num”.This means $num is treated as a string and not as a variable.
[#24] What will be the output of the following PHP code ? <?php function movie ( $int ) { $movies = array( "Fight Club", "Kill Bill", "Pulp Fiction" )
echo "You Do Not Talk About " . $movie [ $integer ]
} movie ( 0 )
?>
Correct Answer
(A) I
Explanation
Solution: Simple use of arrays.
[#25] What will be the output of the following PHP code ? <?php function addFunction ( $num1, $num2 ) { $sum = $num1 + $num2
return $sum
} $return_value = addFunction ( 10 , 20 )
echo "Returned value from the function : " . $return_value ?>
Correct Answer
(C) Returned value from the function : 30
Explanation
Solution: Function returns 30.