Functions singleQuestion_answer
1/50
1.

What will be the output of the following code -

    function fn (&$var) { 
        $var = $var - ($var/10*5);  return $var;  
    }  
    echo fn(100);
2/50
2.

What will be the output of the following PHP code?

<?php
    function calc($num1, $num2)
    {
        $total = $num1 * $num2; 
    }
    $result = calc(42, 0);
    echo $result;    
?>
3/50
3.

The function print_r () returns details on

4/50
4.

What will be the output of the following PHP code?

    <?php
    echo ord ("hi");
    ?>
5/50
5.

What is the best way to test if $param is an anonymous function in a method?

6/50
6.

What will be the output of the following PHP code?

    <?php
    echo chr(52);
    ?>
7/50
7.

What is the difference between the include and require language constructs?

8/50
8.

What will be the output of the following PHP code?

    <?php
    $str = "Hello World";
    echo wordwrap($str,5,"<br>\n");    
    ?>
9/50
9.

What is the output of the following code (Ignoring any PHP notices and error messages)?

    $v1 = 1;
    $v2 = 2;
    $v3 = 3;
    function myFunction(){
        $GLOBALS['v1'] *= 2;
        $v2 *= 2;
        global $v3; $v3 *= 2;
    }
    myFunction();
    echo "$v1$v2$v3";
10/50
10.

What is the output of the following code?

    function func ($x, $x=1, $x=2){
        return $x;
    }
    print func (3);
11/50
11.

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);   
    ?>
12/50
12.

How many functions are used by PHP to convert between arrays and variables?

13/50
13.

What will be the output of the following PHP code?

<?php
    function 2myfunc()
    {
        echo "Hello World";
    }
    2myfunc();
?>
14/50
14.

Functions that returns a new array without disturbing their old arguments might be called as

15/50
15.

When during declaring a function it is impossible to assign a default value to a parameter?

16/50
16.

Some PHP functions, like echo , do not need you to use brackets when calling them. Is this true?

17/50
17.

What is the output of the following function?

    function &find_variable(&$one, &$two, &$three) {
        if ($one > 10 && $one < 20) return $one;
        if ($two > 10 && $two < 20) return $two;
        if ($three > 10 && $three < 20) return $three;
    }
    $one = 2;
    $two = 20;
    $three = 15;
    $var = &find_variable($one, $two, $three);
    $var++;
    echo "1: $one, 2: $two, 3: $three";
18/50
18.

What will be the output of the following PHP code?

  <?php
      echo(atan(0.50));
  ?>
19/50
19.

What is the output of the following code?

<?php
    declare(strict_types=1);
    function multiply(float $a, float $b): int {
        return $a * $b;
    }
    $six = multiply(2, 3);
    echo gettype($six);
?>
20/50
20.

What is the output of the following code?

<?php
    function complicated($compulsory, ...$extras) {
        echo "I have " . func_get_args() . " arguments";
    }
    complicated(1,2,3,4);
21/50
21.

What will be the output of the following PHP code?

    <?php
    echo lcfirst("welcome to Bangladesh");
    ?>
22/50
22.

What is the output of the following code?

<?php
    declare(strict_types=1);
    function multiply(float $a, float $b): float {
        return (double)$a * (double)$b;
    }
    $six = multiply(2, 3);
    echo gettype($six);
23/50
23.

Which one of the following PHP functions can be used to find files?

24/50
24.

Which of the following are valid function names?

i) function()
ii) €()
iii) .function()
iv) $function()
25/50
25.

What will be the output of the following PHP code?

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

You cannot use empty() as a callback for the usort() function.

27/50
27.

Which one of the following functions can be used to compress a string?

28/50
28.

If a function signature contains three parameters, for which of them may the splat operator be used?

29/50
29.

What would you replace ??????? with, below, to make the string Hello, World! be displayed?

                       function myfunction() {
                           /* ??????? */
                           echo $string;
                       }
                       myfunction("Hello, World!");
30/50
30.

What is the output of the following code?

(function Hello() {
    echo "Hello World!";
})();
31/50
31.

What will be the output of the following PHP code?

    <?php
    echo ucwords("i love my country");
    ?>
32/50
32.

What will be the output of the following PHP code?

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

What will be the output of the following PHP code?

<?php
    function A1($x)
    {
        switch($x)
        {
        case 1: 
            //this statement is the same as if($x == 1)
            echo 'Case 1 was executed.';
            break;
        case 2: 
            //this statement is the same as if($x == 2)
            echo 'Case 2 was executed.';
            break;
        case 3: 
            //this statement is the same as if($x == 3)
            echo 'Case 3 was executed.';
            break;
        case 4: 
            //this statement is the same as if($x == 4)
            echo 'Case 4 was executed.';
            break;
        default: 
            //this statement is the same as if $x does not equal the other conditions
            echo 'Default was executed.';
            break;

        }
    }
    A1(9);
?>
34/50
34.

What will this code output?

<?php
    if (!is_callable(function(){echo "Hello";})) {
        function sayHello() {
            echo "World!";
        }
    }
    sayHello();
35/50
35.

Which of the following PHP functions can be used to get the current memory usage?

36/50
36.

What will be the output of the following PHP code?

    <?php
    function foo($msg)
    {
        echo "$msg";
    }
    $var1 = "foo";
    $var1("will this work");
    ?>
37/50
37.

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();
    ?>
38/50
38.

What is the output of the following code?

    $x = function func ($a, $b, $c){
        print "$c|$b|$a\n";
    }
    print $x (1,2,3);
39/50
39.

Take a look at the following code...

<?php
    function myFunction($a){
        $a++;
    }
    $b = 1;
    myFunction($b);
?>

What code do you need to replace so that $b has the value 2 at the end of the script?

40/50
40.

What is the output of the following code?

    function increment ($val){
        return ++$val;
    }
    echo increment (1);
41/50
41.

How would you refer to the parameter with the value cat in the following function? <?php

    function complicated($compulsory, ...$extras, $animal) {
        // I want to reference the variable with the value "cat"
    }
    complicated(1,2,3,"cat");
42/50
42.

What would go in place of ?????? below to make this script execute without a fatal error?

   $a = 1;
   $b = 0;
   /* ?????? */
   $c = $a / $b;
43/50
43.

Type Hinting was introduced in which version of PHP?

44/50
44.

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

45/50
45.

What is the output of the following code?

    function addValues() {
        $sum = 0;
        for ($i = 1; $i <= func_num_args(); $i++){
            $sum += func_get_arg($i);
        }
        return $sum;
    }
    echo addValues(1,2,3);
46/50
46.

Which of the following PHP functions accepts any number of parameters?

47/50
47.

Which of the following PHP functions can be used for generating unique ids?

48/50
48.

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();
    ?>
49/50
49.

What is the best way to ensure that a user-defined function is always passed an object as its single parameter?

50/50
50.

How to define a function in PHP?