ExamVeda
Login
Home
21
What will be the output of the following PHP code?
<?php
function calc($price, $tax="")
 {
    $total = $price + ($price * $tax);
    echo "$total"; 
 }
calc(42);    
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
You can designate certain arguments as optional by placing them at the end of the list and assigning them a default value of nothing.
22
What will be the output of the following PHP code?
<?php
    function a()
    {
        function b()
        {
            echo 'I am b';
        }
        echo 'I am a';
    }
    a();
    a();
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
This will be the output- I am a Fatal error: Cannot redeclare b()
23
What will be the output of the following PHP code?

<?php
    function a()
    {
        function b()
        {
            echo 'I am b';
        }
        echo 'I am a';
    }
    b();
    a();
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
This will be the output- Fatal error: Call to undefined function b(). You cannot call a function which is inside a function without calling the outside function.
24
What will be the output of the following PHP code?

<?php
$op2 = "blabla";
function foo($op1)
{
        echo $op1;
        echo $op2;
}
foo("hello");
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
If you want to put some variables in function that was not passed by it, you must use “global”. Inside the function type global $op2.
25
What will be the output of the following PHP code?
<?php
function foo($msg)
{
    echo "$msg";
}
$var1 = "foo";
$var1("will this work");
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
It is possible to call a function using a variable which stores the function name.
26
What will be the output of the following PHP code?
<?php
   echo "chr(52)";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The chr() function returns a character from the specified ASCII value. Since the ASCII value of 4 is 52, thus 4 was displayed.
27
What will be the output of the following PHP code?
<?php
    echo ord ("hi");
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The ord() function returns the ASCII value of the first character of a string. The ASCII value of h is 104, thus 104 was displayed.
28
What will be the output of the following PHP code?
<?php
   echo(atan(0.50));
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The atan() function returns the arc tangent of arg as a numeric value between -Pi/2 and Pi/2 radians.
29
What will be the output of the following PHP code?
<?php
   define("GREETING","Hello you! How are you today?");
   echo constant("GREETING");
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The define() function defines a constant.
30
What will be the output of the following PHP code?
<?php
define("GREETING1","Hello you! How are you today?");
define("GREETING2","Hello you! How are you today?");
define("GREETING3","Hello you! How are you today?");
echo defined("GREETING");
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The defined() function checks whether a constant exists.