PHP Language | 10 Minute‐Test 7


Instruction

  • Total number of questions : 10.
  • Time alloted : 10 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

Which of the following php statement/statements will store 111 in variable num?
i) int $num = 111;
ii) int mum = 111;
iii) $num = 111;
iv) 111 = $num;

A.
Both i) and ii)
B.
All of the mentioned.
C.
Only iii)
D.
Only i)

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

You need not specify the datatype in php.

2.

Which of the below statements is equivalent to $add += $add ?

A.
$add = $add
B.
$add = $add +$add
C.
$add = $add + 1
D.
$add = $add + $add + 1

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

a += b is an addition assignment whose outcome is a = a + b. Same can be done with subtraction,multiplication,division etc.

3.

What will be the output of the following PHP code?

    <?php

    $user = array("Ashley", "Bale", "Shrek", "Blank");

    for ($x=0; $x < count($user); $x++)

       {

        if ($user[$x] == "Shrek") continue;

            printf ($user[$x]);

    }

    ?>

A.
AshleyBale
B.
AshleyBaleBlank
C.
ShrekBlank
D.
Shrek

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The continue statement causes execution of the current loop iteration to end and commence at the beginning of the next iteration.

4.

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

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.

5.

What will be the output of the following PHP code?

    <?php

        echo ord("hi");

    ?>

A.
106
B.
103
C.
104
D.
209

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

expl

6.

What will be the output of the following PHP code?

    <?php

    $fruits = array ("apple", "orange", "banana");

    echo (next($fruits));

        echo (next($fruits));

    ?>

A.
orangebanana
B.
appleorange
C.
orangeorange
D.
appleapple

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The next() function returns the array value residing at the position immediately following that of the current array pointer.

7.

What will be the output of the following PHP code ?

<?php

$people = array("Peter", "Susan", "Edmund", "Lucy");

echo pos($people);

?>

A.
Lucy
B.
Peter
C.
Susan
D.
Edmund

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The pos() function returns the value of the current element in an array, and since no operation has been done, the current element is the first element.

8.

What will be the output of the following PHP code?

<?php

$a1 = array_fill(3, 4, "blue");

$b1 = array_fill(0, 1, "red");

print_r($a1);echo "<br>";

print_r($b1);

?>

A.
Array ( [3] => blue [4] => blue)
Array ( [0] => red )
B.
Array ( [4] => blue [5] => blue [6] => blue)
Array ( [0] => red )
C.
Array ( [3] => blue [4] => blue [5] => blue [6] => blue )
Array ()
D.
Array ( [3] => blue [4] => blue [5] => blue [6] => blue )
Array ( [0] => red )

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The array_fill() function fills an array with values.

9.

What will be the output of the following PHP code?

    <?php

    $fruits = array ("apple", "mango", "peach", "pear",    "orange");

    $subset = array_slice ($fruits, 2);

    print_r ($subset);

    ?>

A.
Array ( [0] => peach )
B.
Array ( [0] => apple [1] => mango [2] => peach )
C.
Array ( [0] => apple [1] => mango )
D.
Array ( [0] => peach [1] => pear [2] => orange )

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The array_slice() function returns a section of an array based on a starting and ending offset value.

10.

Which one of the following is the right way to call a class constant, given that the class is mathFunction?

A.
echo PI;
B.
echo mathFunction->PI;
C.
echo mathFunction::PI;
D.
echo mathFunction=PI;
Submit your test now to view the Results and Statistics with answer explanation.