This quiz tests your knowledge of functions in PHP, covering function declarations, parameters, return types, and anonymous functions.
Question 2
What is the purpose of the return statement in PHP functions?
It stops the execution of the function.
It sends a value back to the function caller.
It prints the output directly.
It defines the function's parameters.
Question 3
Which of the following PHP functions is used to calculate the length of a string?
strlen()
substr()
strpos()
explode()
Question 4
How do you pass arguments to a function in PHP?
By calling the function with parameters
By using the pass()
keyword
By defining variables inside the function
Arguments are not needed in PHP functions
Question 5
What does the array_push()
function do in PHP?
Removes an element from the beginning of the array
Adds an element to the end of the array
Sorts the array in ascending order
Merges two arrays
Question 6
What is the purpose of anonymous functions in PHP?
To call functions recursively
To define functions without names, often for passing as arguments
To create private functions
To define default functions
Question 7
Which PHP function is used to convert a string to a date format?
strtotime()
date()
time()
mktime()
Question 8
Which PHP function is used to get the current date or time?
time()
date()
current()
getTime()
Question 9
What is the output of the following code?
function add($a, $b) {
return $a + $b;
}
echo add(5, 3);
53
8
5 + 3
Error
Question 10
What is the result of the following PHP code?
function greet($name) {
return "Hello, " . $name;
}
echo greet("Shubham");
Hello, Shubham
Hello,
Shubham
Error
There are 10 questions to complete.