}
}
inner();
?> | PHP | MYTAT"> }
}
inner();
?> | PHP | MYTAT">
Q
What will be the output of the following PHP code?

<?php
function outer() {
function inner() {
echo 'Inner function';
}
}
inner();
?>

Answer & Solution

Answer: Option B
Solution:
The output of the code will be Function does not exist: inner because the inner function inner() is defined within the outer() function and is not accessible outside of it. Attempting to call inner() directly results in an error since it is not defined in the global scope.
Related Questions on Average

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 of the following statements is true about function names in PHP?

A). Function names are case-sensitive

B). Function names must start with a dollar sign ($)

C). Function names cannot contain numbers

D). Function names can contain spaces

What is the syntax for calling a function in PHP?

A). callFunction()

B). function callFunction()

C). callFunction

D). callFunction;

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 significance of passing functions as arguments in PHP?

A). It allows functions to be called multiple times

B). It simplifies the function definition process

C). It enables dynamic function invocation and behavior

D). It prevents code duplication

What will be the output of the following PHP code?

<?php
$greet = function($name) {
return 'Hello, $name!';
};
echo $greet('John');
?>

A). Hello, John!

B). Hello, $name!

C). function($name) {
return 'Hello, $name!';
}

D). John

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

A). vararg

B). args

C). params

D). ...$args

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()

What is the significance of default parameter values in PHP functions?

A). Default parameter values are required for all parameters in a function

B). Default parameter values allow specifying multiple default values for a parameter

C). Default parameter values allow parameters to be optional

D). Default parameter values allow specifying the data type of parameters

What is the purpose of the return statement in PHP functions?

A). To terminate the function execution

B). To output a value from the function and terminate its execution

C). To define the function name

D). To declare a variable within the function