}
}
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

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

What is the output of the following PHP code?

<?php
$num = 10;
function testScope() {
global $num;
echo $num;
}
testScope();
?>

A). 10

B). 0

C). Undefined variable: num

D). Variable $num cannot be accessed outside the function

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

Which PHP feature allows defining functions without specifying their names?

A). Anonymous functions

B). Dynamic functions

C). Global functions

D). Static functions

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

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 will be the output of the following PHP code?

<?php
function uppercase($str) {
return strtoupper($str);
}
echo uppercase('hello');
?>

A). HELLO

B). hello

C). Uppercase

D). Undefined function: uppercase

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

A). Dynamic functions

B). Global functions

C). Static functions

D). Callbacks

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!'; }

Which PHP feature allows defining functions within other functions?

A). Nested functions

B). Inner functions

C). Enclosed functions

D). Internal functions