ExamVeda
Login
Home
31
What will be the output of the following PHP code?
<?php
function sum($num1, $num2)
{
    $total = $num1 + $num2;
    echo "chr($total)"; 
}
$var1 = "sum";
$var1(5, 44);    
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
It is possible to call a function using a variable which stores the function name also the chr() function returns a character from the specified ASCII value.
32
What will be the output of the following PHP code?
<?php
function sum($num1, $num2)
{
    $total = $num1 + $num2;
    echo "cos($total)"; 
}
sum(5,-5);    
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
cos() gives the cos value of the argument. Here the function returns 1.
33
What will be the output of the following PHP code?
<?php
function b()
{
    echo "b is executed";
}
function a()
{
    b();
    echo "a is executed";
    b();
}
a();
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
imple order of execution.
34
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:
Functions returns value 30.
35
What will be the output of the following PHP code?
<?php
function sayHello()
{
   echo "HelloWorld<br />";
}
$function_holder = "sayHello";
$function_holder();
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
It is possible to assign function names as strings to variables and then treat these variables exactly as you would the function name itself.
36
What will be the output of the following PHP code?
span>
function one()
{
    echo " this works";
    function two()
    {
        echo "this too works";
    }
}
one();
two();
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Two is declared in one and is called after one.Hence it works.
37
What will be the output of the following PHP code?
<?php
function do($myString)
{
    echo strpos($myString, "donkey",0);
}
do("The donkey looks like a horse.");
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Donkey starts from position 4 in string.
38
What will be the output of the following PHP code?
<?php
function onespan>()
{
    define("const","I am awesome!");
    echo constant("const");
}
one();
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Using the define function to define the constant “const”.
39
What will be the output of the following PHP code?
<?php
    $title = "O'malley wins the heavyweight championship!";
    echo ucwords($title);
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The ucwords() function capitalizes the first letter of each word in a string. Its prototype follows: string ucwords(string str).
40
What will be the output of the following PHP code?
<?php
    echo str_pad("Salad", 5)." is good.";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The str_pad() function pads a string with a specified number of characters.