ExamVeda
Login
Home
61
What will be the output of the following PHP code ?
<?php
function test($int)
{
    if ($int == 1)
        echo "This Works";
    if ($int == 2)
        echo "This Too Seems To Work";
}
test(1);
TEST(2);
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Function Is case Insensitive.
62
What will be the output of the following PHP code ?
<?php
function mine($num)
{
    $num = 2 + $num;
    echo $num;
}
mine(3);
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Simple arithmetic operation.
63
What will be the output of the following PHP code ?
<?php
function mine($num)
{
    $num = 2 + $num;
    echo "$num";
}
mine(3);
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The function is defined as echo “$num”.This means $num is treated as a string and not as a variable.
64
What will be the output of the following PHP code ?
<?php
function movie($int)
{
    $movies = array("Fight Club", "Kill Bill", "Pulp Fiction");
    echo "You Do Not Talk About ". $movie[$integer];
}
movie(0);
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Simple use of arrays.
65
What will be the output of the following PHP code ?
<?php
function addFunction($num1, $num2)
{
    $sum = $num1 + $num2;
    return $sum;
}
$return_value = addFunction(10, 20);
echo "Returned value from the function : " .$return_value
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Function returns 30.
66
What will be the output of the following PHP code ?
<?php
function time($string)
{
    echo strtr("Towe Pa55", "ow5", $string);
}
time("ims");
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The strtr() function translates certain characters in a string.
67
What will be the output of the following PHP code ?
<?php
function constant()
{
    define("GREETING", "Welcome to Narnia");
    echo greeting;
}
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
By default constants are case sensitive. Hence an error will arise.
68
What will be the output of the following PHP code ?
<?php
function constant()
{
    define("GREETING", "Welcome to Narnia",true);
    echo greeting;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
By default constants are case sensitive. But the third parameter in define(), if set to true, makes constants case insensitive.
69
What will be the output of the following PHP code ?
<?php
function start($string)
{
    if ($string < 45)
        return 20;
    else
        return 40;
}
$t = start(90);
if ($t < 20)
{
    echo "Have a good day!";
}
else
{
    echo "Have a good night!";
}
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Function returns 40. this is greater than 20, hence the output.
70
What will be the output of the following PHP code ?
<?php
function email()
{
    $email = ’contact@examveda.com’;
    $new = strstr($email, ‘@');
    echo $new;
}
email();
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The strstr() function searches for the first occurrence of a string inside another string.