Q
Which PHP feature allows defining functions without specifying their names?

Answer & Solution

Answer: Option A
Solution:
Anonymous functions in PHP, also known as closures, allow defining functions without specifying their names. They can be assigned to variables or passed as arguments to other functions.
Related Questions on Average

Which PHP feature allows defining functions within other functions?

A). Nested functions

B). Inner functions

C). Enclosed functions

D). Internal functions

Which PHP keyword is used to declare a variable-length argument list in a function?

A). vararg

B). args

C). params

D). ...$args

Which of the following statements about return types in PHP functions is true?

A). PHP functions must always have a return type

B). PHP functions can have a return type specified using the 'returns' keyword

C). PHP functions can have a return type specified using the 'return' keyword

D). PHP functions can have a return type declared using type declarations

Which PHP keyword is used to check if a function exists before calling it?

A). check_function()

B). function_exists()

C). function_check()

D). exists_function()

Which of the following statements about variable scope in PHP functions is true?

A). Variables defined inside a function have global scope

B). Variables defined outside a function have local scope

C). Variables defined inside a function have local scope

D). Variables defined outside a function have global scope

Which PHP feature allows passing a function as an argument to another function?

A). Dynamic functions

B). Global functions

C). Static functions

D). Callbacks

How do you define parameters in a PHP function?

A). Parameters are defined within parentheses after the function name

B). Parameters are defined using the keyword 'param'

C). Parameters are defined using curly braces {}

D). Parameters are defined using square brackets []

What is the output of the following PHP code?

<?php
function multiply(...$args) {
$result = 1;
foreach ($args as $value) {
$result *= $value;
}
return $result;
}
echo multiply(2, 3, 4);
?>

A). 24

B). 9

C). 6

D). 2

What is the output of the following PHP code?

<?php
function greet() {
echo 'Hello, World!';
}
if (function_exists('greet')) {
greet();
} else {
echo 'Function does not exist';
}
?>

A). Hello, World!

B). Function does not exist

C). Undefined function: greet

D). Function greet() { echo 'Hello, World!'; }

What is the syntax for calling a function in PHP?

A). callFunction()

B). function callFunction()

C). callFunction

D). callFunction;