PHP Functions
- What will be the output of the following PHP code?
<?php
function n()
{
function m()
{
echo 'M';
}
echo 'N';
}
m();
n();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
This will be the output- Fatal error: Call to undefined function m(). You cannot call a function which is inside a function without calling the outside function.
- What will be the output of the following PHP code?
<?php
function calculate($p, $t="")
{
$total = $p + ($p * $t);
echo "$total";
}
calculate(65);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
You can designate certain arguments as optional by placing them at the end of the list and assigning them a default value of nothing.
- What will be the output of the following PHP code?
<?php
function n()
{
function m()
{
echo 'M';
}
echo 'N';
}
n();
n();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
This will be the output- I am a Fatal error: Cannot redeclare b()
- What will be the output of the following PHP code?
<?php
define("GREETING1","Welcome to interview mania!");
define("GREETING2","Welcome to interview mania!");
define("GREETING3","Welcome to interview mania!");
echo defined("GREETING");
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The defined() function checks whether a constant exists.
- What will be the output of the following PHP code?
<?php
$option2 = "Hey";
function fun($option1)
{
echo $option1;
echo $option2;
}
fun("Welcome");
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
If you want to put some variables in function that was not passed by it, you must use “global”. Inside the function type global $option2.