PHP Functions
- What will be the output of the following PHP code ?
<?php
function Calculate($p,$q)
{
echo ($p + $q);
echo "\n";
echo ($p - $q);
echo "\n";
echo ($p * $q);
echo "\n";
echo ($p / $q);
echo "\n";
echo ($p % $q);
}
Calculate(20,16);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Simple usage of all arithmetic operators.
- What will be the output of the following PHP code ?
<?php
function fun($opt)
{
switch($opt)
{
case 10:
echo 'Case 10 will execute.';
break;
case 20:
echo 'Case 20 will execute.';
break;
case 30:
echo 'Case 30 will execute.';
break;
case 40:
echo 'Case 40 will execute.';
break;
default:
echo 'Default will execute.';
break;
}
}
fun(20);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The switch statement is executed with $opt = 20.
- What will be the output of the following PHP code ?
<?php
function uppercase($str)
{
echo ucwords($str);
}
$fun = "uppercase";
$fun("time to do a great job.");
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The ucwords() function converts the first character of each word in a string to uppercase.
- What will be the output of the following PHP code ?
<?php
function fun($str)
{
echo "my favourite fun time is ".$str;
function m()
{
echo " to spend with friends";
}
}
m();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
m is undeclared if fun() is not called first.
- What will be the output of the following PHP code ?
<?php
function fun($str)
{
echo "favourite fun time is ".$str;
function b()
{
echo "Inside block executed...";
}
}
function p()
{
echo "Outside block executed...";
}
p();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
This one works because p is declared independent of fun() also.