PHP Functions MCQs
PHP Functions MCQs : This section focuses on "Functions" in PHP. These Multiple Choice Questions (mcq) should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. How many types of functions are available in php?
A. 5
B. 4
C. 3
D. 2
View Answer
Ans : D
Explanation: PHP provides us with two major types of functions Built-in functions and User Defined Functions.
2. Which of the following is not a built-in function in php ?
A. print_r()
B. fopen()
C. fclosed()
D. gettype()
View Answer
Ans : C
Explanation: fclosed() is not a built-in function in php.
3. Why should we use functions?
A. Reusability
B. Easier error detection
C. Easily maintained
D. All of the above
View Answer
Ans : D
Explanation: we use functions beacause it provide Reusability, Easier error detection, Easily maintained.
4. A function name always begins with the keyword _________.
A. fun
B. def
C. function
D. None of the above
View Answer
Ans : C
Explanation: A function name always begins with the keyword function.
5. A function name cannot start with a ____
A. alphabet
B. underscore
C. number
D. Both C and B
View Answer
Ans : C
Explanation: A function name cannot start with a number. It can start with an alphabet or underscore.
6. A function name is not case-sensitive?
A. True
B. False
C. Only user-defined function is case-sensitive
D. None of the above
View Answer
Ans : A
Explanation: A function name is not case-sensitive, the following statement is true.
7. A function name is not case-sensitive?
<?php
function funclfc()
{
echo "This is letsfindcourse";
}
// Calling the function
funclfc();
?>
A. This is lfc
B. This is letsfindcourse
C. No Output
D. Error
View Answer
Ans : B
Explanation: The output of the following PHP code This is letsfindcourse.
8. A function name is not case-sensitive?
<?php
function prolfc($num1, $num2, $num3)
{
$mul = $num1 * $num2 * $num3;
echo "The product is $mul";
}
prolfc(1, 2, 3, 4);
?>
A. 24
B. 8
C. 6
D. Error: to many argument.
View Answer
Ans : C
Explanation: The output of the following PHP code is 6.
9. Type Hinting was introduced in which version of PHP?
A. PHP 5.1
B. PHP 5
C. PHP 5.3
D. PHP 5.4
View Answer
Ans : B
Explanation: PHP 5 introduced the feature of type hinting. With the help of type hinting, we can specify the expected data type of an argument in a function declaration.
10. A function in PHP which starts with double underscore is known as __________.
A. Magic Function
B. Inbuilt Function
C. Default Function
D. User Defined Function
View Answer
Ans : A
Explanation: PHP functions that start with a double underscore - a "__" are called magic functions in PHP.
11. PHP has over ____________ built-in functions that can be called directly.
A. 10
B. 100
C. 1000
D. 10000
View Answer
Ans : C
Explanation: PHP has over 1000 built-in functions that can be called directly
12. Function names are case-sensitive.
A. True
B. False
C. Only Built-In function
D. Only User-defined function
View Answer
Ans : B
Explanation: Function names are NOT case-sensitive.
13. how to declare strict requirement in php 7?
A. select(strict_types=1);
B. declare(strict_types=0);
C. declare(strict_types=1);
D. select(strict_types=0);
View Answer
Ans : C
Explanation: declare(strict_types=1); syntax is used to declare strict requirement in php 7.
14. where in code we declare strict requirement in php 7?
A. the very first line of the PHP file
B. the very last line of the PHP file
C. After declaring variable
D. Anywhere in the code.
View Answer
Ans : A
Explanation: we declare strict requirements in PHP 7 the very first line of the PHP file.
15. What will be the output of the following code?
<?php declare(strict_types=1); // strict requirement
function addNumbers(int $a, int $b) {
return $a + $b;
}
echo addNumbers(5, "5 days");
?>
A. 5+5days
B. 55days
C. No Output
D. Error
View Answer
Ans : D
Explanation: since strict is enabled and "5 days" is not an integer, an error will be thrown.
16. What will be the output of the following code?
<?php declare(strict_types=1); // strict requirement ?>
<?php
function setHeight(int $minheight = 50) {
echo "The height is : $minheight <br>";
}
setHeight(350);
?>
A. The height is : 350
B. The height is : 50
C. No Output
D. Error
View Answer
Ans : A
Explanation: The height is: 350 be the output of the following code.
17. Which one of the following functions displays PHP interpreter settings bound to web server?
A. infophp()
B. phpinfo()
C. php_info()
D. info_php()
View Answer
Ans : B
Explanation: phpinfo() of the following functions displays PHP interpreter settings bound to web server.
18. Which of the following functions help in navigating to another php page?
A. header()
B. location()
C. redirect()
D. None of the above
View Answer
Ans : A
Explanation: header() of the following functions help in navigating to another PHP page.
19. In which of the following cases would function empty() return FALSE?
A. $x; echo empty($x);
B. $x=FALSE; echo empty($x);
C. $x=TRUE; echo empty($x);
D. $x=NULL; echo empty($x);
View Answer
Ans : C
Explanation: $x=TRUE; echo empty($x); of the following cases would function empty() return FALSE.
20. What will be the output of the following code?
<?php
function WRITEMSG() {
echo "Hello world!";
}
writemsg();
?>
A. Hello world!
B. Null
C. No Output
D. None of the above
View Answer
Ans : A
Explanation: Hello world! be the output of the following code because Function names are NOT case-sensitive.
Also check :
Discussion