PHP Language | 10 Minute‐Test 6


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.

We can use ___ to comment a single line?
i) /?
ii) //
iii) #
iv) /* */

A.
Only ii)
B.
i), iii) and iv)
C.
ii), iii) and iv)
D.
Both ii) and iv)

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

/* */ can also be use to comment just a single line although it is used for paragraphs. // and # are used only for single line comment.

2.

What will be the output of the following PHP code?

    <?php

    $total = "25 students";

    $more = 10;

    $total = $total + $more;

    echo "$total";

    ?>

A.
Error
B.
35 students
C.
35
D.
25 students

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The integer value at the beginning of the original $total string is used in the calculation. However if it begins with anything but a numerical value, the value will be 0.

3.

Which of the looping statements is/are supported by PHP?
i) for loop
ii) while loop
iii) do-while loop
iv) foreach loop

A.
i) and ii)
B.
i), ii) and iii)
C.
All of the mentioned
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

4.

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 b
B.
I am bI am a
C.
Error
D.
I am a Error

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

This will be the output- I am a Fatal error: Cannot redeclare b()

5.

What will be the output of the following PHP code?

    <?php

        echo "char(52)";

    ?>

A.
1
B.
2
C.
3
D.
4

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The chr() function returns a character from the specified ASCII value. Since the ASCII value of 4 is 52, thus 4 was displayed.

6.

What will be the output of the following PHP code?

    <?php

    $state = array ("Karnataka", "Goa", "Tamil Nadu",

    "Andhra Pradesh");

    echo (array_search ("Tamil Nadu", $state) );

    ?>

A.
True
B.
1
C.
False
D.
2

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The array_search() function searches an array for a specified value, returning its key if located and FALSE otherwise.

7.

What will be the output of the following PHP code ?

<?php

$city_west = array("NYC", "London");

$city_east = array("Mumbai", "Beijing");

print_r(array_replace($city_west, $city_east));

?>

A.
Array ( [1] => Mumbai [0] => Beijing )
B.
Array ( [0] => NYC [1] => London )
C.
Array ( [1] => NYC [0] => London )
D.
Array ( [0] => Mumbai [1] => Beijing )

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The array_replace() function replaces the values of the first array with the values from following arrays

8.

What will be the output of the following PHP code?

<?php

$a1 = array("a"=>"red", "b"=>"green", "c"=>"blue", "d"=>"yellow");

$a2 = array("e"=>"red", "f"=>"green", "g"=>"blue");

$result = array_diff($a1, $a2);

print_r($result);

?>

A.
Array ( [d] => yellow )
B.
Array ( [c] => blue )
C.
Array ( [a] => red )
D.
Array ( [e] => yellow )

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The array_diff() function compares the values of two (or more) arrays, and returns the differences.

9.

What will be the output of the following PHP code?

    <?php

    $face = array ("A", "J", "Q", "K");

    $number = array ("2","3","4", "5", "6", "7", "8", "9", "10");

    $cards = array_merge ($face, $number);

    print_r ($cards);

    ?>

A.
Array ( [0] => A [1] => J [2] => Q [3] => K [4] => 2 [5] => 3 [6] => 4 [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )
B.
Array ( [0] => A [1] => 2 [2] => J [3] => 3 [4] => Q [5] => 4 [6] => K [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )
C.
Error
D.
Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 7 [6] => 8 [7] => 9 [8] => 10 [9] => A [10] => J [11] => Q [12] => K )

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The resulting array will begin with the first input array parameter, appending each subsequent array parameter in the order of appearance.

10.

Which one of the following is the right way to define a constant?

A.
constant PI = “3.1415”;
B.
const $PI = “3.1415”;
C.
constant PI = ‘3.1415’;
D.
const PI = ‘3.1415’;
Submit your test now to view the Results and Statistics with answer explanation.