PHP Functions
- What will be the output of the following PHP code?
<?php
function First()
{
echo "Function First executed...\n";
function Second()
{
echo "Function Second executed...";
}
}
First();
Second();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Second is declared in First and is called after First.Hence it works.
- What will be the output of the following PHP code?
<?php
function addation($n1, $n2)
{
$add = $n1 + $n2;
return $add;
}
$return_val = addation(50, 70);
echo "Returned value : $return_val"
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Functions returns value 120.
- What will be the output of the following PHP code?
<?php
function HelloFuncation()
{
echo "Hello Interview Mania\n";
}
$fun_holder = "HelloFuncation";
$fun_holder();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
It is possible to assign function names as strings to variables and then treat these variables exactly as you would the function name itself.
- What will be the output of the following PHP code?
<?php
function calc1(&$n)
{
$n += 7;
}
function calc2(&$n)
{
$n += 8;
}
$OrignalNumber = 12;
calc1( $OrignalNumber );
echo "Original Number is $OrignalNumber\n";
calc2( $OrignalNumber );
echo "Original Number is $OrignalNumber\n";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
calc2() passes value of the variable by reference.
- What will be the output of the following PHP code?
<?php
function fun($Str)
{
echo strpos($Str, "good",0);
}
fun("The Interview Mania is good for study.");
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
good starts from position 23 in string.