Functions
1.

How to define a function in PHP?

A.  

function {function body}

B.  

data type functionName(parameters) {function body}

C.  

functionName(parameters) {function body}

D.  

function functionName(parameters) {function body}

2.

Type Hinting was introduced in which version of PHP?

A.  

PHP 4

B.  

PHP 5

C.  

PHP 5.3

D.  

PHP 6

3.

Which type of function call is used in line 8 in the following PHP code?

 <?php
    function calc($price, $tax)	
    {
        $total = $price + $tax;
    }
    $pricetag = 15;
    $taxtag = 3;
    calc($pricetag, $taxtag);	
    ?>
A.  

Call By Value

B.  

Call By Reference

C.  

Default Argument Value

D.  

Type Hinting

4.

 What will be the output of the following PHP code?

 <?php
    function calc($price, $tax="")
    {
        $total = $price + ($price * $tax);
        echo "$total"; 
    }
    calc(42);	
    ?>
A.  

Error

B.  

0

C.  

42

D.  

84

5.

Which of the following are valid function names?

i) function()
ii) €()
iii) .function()
iv) $function()
A.  

Only i)

B.  

Only ii)

C.  

i) and ii)

D.  

iii) and iv)

6.

Which of the following are valid function names?

i) function()
ii) €()
iii) .function()
iv) $function()
A.  

Only i)

B.  

Only ii)

C.  

i) and ii)

D.  

iii) and iv)

7.

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();
    ?>
A.  

I am a

B.  

I am bI am a

C.  

Error

D.  

I am a Error

8.

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();
    ?>
A.  

I am b

B.  

I am bI am a

C.  

Error

D.  

I am a Error

9.

What will be the output of the following PHP code?


<?php
    $op2 = "blabla";
    function foo($op1)
    {
        echo $op1;
        echo $op2;
    }
    foo("hello");
    ?>
A.  

helloblabla

B.  

Error

C.  

hello

D.  

helloblablablabla

10.

A function in PHP which starts with __ (double underscore) is known as __________

A.  

Magic Function

B.  

Inbuilt Function

C.  

Default Function

D.  

User Defined Function