PHP Questions and Answers – Functions – Part 1
This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “PHP Functions”.
1. Why should we use functions?
A Easily maintained
B Reusability
C Easier error detection
D All of the above
2. How many categories of functions are there in PHP?
A 1
B 2
C 3
D 4
3. Which function is not a built-in function in PHP ?
A fopen()
B print()
C addNumber()
D gettype()
4. How to define a function in PHP?
A function {function body}
B datatype functionName(parameters) {function body}
C functionName(parameters) {function body}
D function functionName(parameters) {function body}
5. Type Hinting was provided in which version of PHP?
A PHP 4
B PHP 5
C PHP 5.3
D PHP 6
6. A function always starts with the keyword _______
A def
B function
C fun
D None of the above
7. A function’s name cannot begin with a _______.
A number
B underscore
C alphabet
D Both A and B
8. A function name is not case-sensitive?
A False
B True
C Only user-defined function is case-sensitive
D None of the above
9. What is the result of the following PHP code?
<?php function calculate($cost, $tax="") { $total = $cost + ($cost * $tax); echo "$total"; } calculate(5); ?>
A 0
B 5
C 25
D Error
10. What is the type of function call used in line 10 in the following code?
<?php function add($n1, $n2) { $sum = $n1 + $n2; } $n1 = 2; $n2 = 4; add($n1, $n2); ?>
A Call By Reference
B Call By Value
C Call By Address
D Default Argument Value