PHP Functions
- What will be the output of the following PHP code ?
<?php
function constant()
{
define("MESSAGE", "Welcome to Interview Mania");
echo MESSAGE;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
By default constants are case sensitive. Hence an error will arise.
- What will be the output of the following PHP code ?
<?php
function fun($str)
{
if ($str < 50)
return 30;
else
return 60;
}
$p = fun(100);
if ($p < 30)
{
echo "Hello!";
}
else
{
echo "Hey!";
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Function returns 60. this is greater than 30, hence the output.
- What will be the output of the following PHP code ?
<?php
function fun()
{
ECHO "Hello Interview Mania!\n";
echo "Hello Interview Mania!\n";
EcHo "Hello Interview Mania!\n";
}
fun();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Functions, keywords etc) in php are case insensitive.
- What will be the output of the following PHP code ?
<?php
function fun()
{
$EmailId1 = "Interview@Mania.com";
$EmailId2 = strstr($EmailId1, '@');
echo $EmailId2;
}
fun();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The strstr() function searches for the first occurrence of a string inside another string.
- What will be the output of the following PHP code ?
<?php
function str()
{
echo strstr("Interview Mania!", 118);
}
str();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
118 is the ASCII value of v.