PHP Language | 20 Minute‐Test 9


Instruction

  • Total number of questions : 20.
  • Time alloted : 20 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’;

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Class constants are created like: const NAME = ‘VALUE’;

11.

Which one of the following functions is used to determine object type?

A.
obj_type()
B.
type()
C.
is_a()
D.
is_obj()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The is_a() function returns true if object belongs to a class type or if it belongs to a class that is a child of that class. Or else false is returned.

12.

If one intends to create a model that will be assumed by a number of closely related objects, which class must be used?

A.
Normal class
B.
Static class
C.
Abstract class
D.
Interface

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

13.

Which version introduced the function error_get_last()?

A.
PHP 4
B.
PHP 5
C.
PHP 5.2
D.
PHP 5.3

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

This function returns an associative array consisting of the type, message, file, and line of the last occurring error.

14.

You can extend the exception base class, but you cannot override any of the preceding methods because the are declared as..

A.
protected
B.
final
C.
static
D.
private

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Marking a method as final prevents it from being overridden by a subclass.

15.

What will be the output of the following PHP code?

    <?php

    $var=300;

    $int_options = array("options"=>array ("min_range"=>0, "max_range"=>256));

    if (!filter_var($var, FILTER_VALIDATE_INT, $int_options))

        echo("Integer is not valid");

    else

        echo("Integer is valid");

    ?>

A.
No output is returned
B.
Integer is not valid
C.
Integer is valid
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Since the integer is “300” it is not in the specified range, and the output of the code above will be: “Integer is not valid”.

16.

POSIX implementation was deprecated in which version of PHP?

A.
PHP 4
B.
PHP 5
C.
PHP 5.2
D.
PHP 5.3

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None

17.

What will be the output of the following PHP code?

    <?php

    echo str_pad("Salad", 5)." is good.";

    ?>

A.
SaladSaladSaladSaladSalad is good
B.
is good SaladSaladSaladSaladSalad
C.
is good Salad
D.
Salad is good

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The str_pad() function pads a string with a specified number of characters.

18.

Which one of the following function operates similarly to fgets(), except that it also strips any HTML and PHP tags form the input?

A.
fgetsh()
B.
fgetsp()
C.
fgetsa()
D.
fgetss()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None

19.

Which one of the following function is useful for producing a timestamp based on a given date and time.

A.
time()
B.
mktime()
C.
mrtime()
D.
mtime()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None

20.

Which of the following statements can be used to set the time zone in individual scripts?

A.
date_set_timezone(‘Europe/London’);
B.
date_default_timezone_set(‘Europe/London’);
C.
date_set_default_timezone(‘Europe/London’);
D.
date_default_timezone(‘Europe/London’);

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

You can also use ini_set(‘date.timezone’, ‘Europe/London’);.

Submit your test now to view the Results and Statistics with answer explanation.