PHP Functions
- What will be the output of the following PHP code?
<?php
function fun($message)
{
echo "$message";
}
$var = "fun";
$var("Executed...");
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
It is possible to call a function using a variable which stores the function name.
- 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.
- 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 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
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.