PHP Language | 20 Minute Test


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.

Which of the below symbols is a newline character?

A.
\r
B.
\n
C.
/n
D.
/r

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

PHP treats \n as newline character.

2.

What does PHP stand for?
i) Personal Home Page
ii) Hypertext Preprocessor
iii) Pretext Hypertext Processor
iv) Preprocessor Home Page

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

PHP previously stood for Personal Home Page now stands for Hypertext Preprocessor.

3.

Which version of PHP introduced Try/catch Exception?

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Version 5 added support for Exception Handling.

4.

What will be the output of the following code?

<?php

    $foo = 'Bob';             

    $bar = &$foo;             

    $bar = "My name is $bar"; 

    echo $bar;

    echo $foo;

?>

A.
Error
B.
My name is BobBob
C.
My name is BobMy name is Bob
D.
My name is Bob Bob

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The $bar = &$foo; line will reference $foo via $bar.

5.

Which statement will output $x on the screen?

A.
echo “\$x‿;
B.
echo “$$x‿;
C.
echo “/$x‿;
D.
echo “$x;‿;

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

A backslash is used so that the dollar sign is treated as a normal string character rather than prompt PHP to treat $x as a variable. The backslash used in this manner is known as escape character.

6.

Which of the conditional statements is/are supported by PHP?
i) if statements
ii) if-else statements
iii) if-elseif statements
iv) switch statements

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

7.

If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?

A.
12
B.
1
C.
Error
D.
5

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

?: is known as ternary operator. If condition is true then the part just after the ? is executed else the part after : .

8.

Who is the father of PHP?

A.
Rasmus Lerdorf
B.
Willam Makepiece
C.
Drek Kolkevi
D.
List Barely

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

9.

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()

10.

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

A.
glob()
B.
file()
C.
fold()
D.
get_file()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Here is an example-
// get all php files AND txt files
$files = glob(‘*.{php,txt}’, GLOB_BRACE);
print_r($files);
/* output looks like:
Array
(
[0] => phptest.php
[1] => pi.php
[2] => post_output.php
.
.
.
)

11.

What will be the output of the following PHP code?

<?php

    $str = "Hello World"

    echo wordwrap($str,5,"<br>\n");   

    ?>

A.
Hello World
B.
Hello
World
C.
Hell
o wo
rld
D.
World

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Explanation:The wordwrap() function wraps a string into new lines when it reaches a specific length.

12.

Which of the following are correct ways of creating an array?
i) state[0] = “karnataka‿;
ii) $state[] = array(“karnataka‿);
iii) $state[0] = “karnataka‿;
iv) $state = array(“karnataka‿);

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

A variable name should start with $ symbol which is not present in i) and you need not put the square brackets when you use the array() constructor.

13.

Which function will return true if a variable is an array or false if it is not?

A.
this_array()
B.
is_array()
C.
do_array()
D.
in_array()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

A built-in function, is_array(), is available for testing an array. Its prototype follows: boolean is_array(mixed variable).

14.

Which function returns an array consisting of associative key/value pairs?

A.
count()
B.
array_count()
C.
array_count_values()
D.
count_values()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

15.

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.

16.

Which of the following statements is/are true about Constructors in PHP?
i) PHP 4 introduced class constructors.
ii) Constructors can accept parameters.
iii) Constructors can call class methods or other functions.
iv) Class constructors can call on other constructors.

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

17.

In the PHP code given below, what is/are the properties?

   <?php

    class Example

    {

        public $name;

        function Sample()

        {

            echo "This is an example";

        }

    }

    ?>

A.
echo “This is an example‿;
B.
public $name;
C.
class Example
D.
function sample()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Yes they are nothing but variables.

18.

The class from which the child class inherits is called..
i) Child class
ii) Parent class
iii) Super class
iv) Base class

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

19.

Which magic method is used to implement overloading in PHP?

A.
__call
B.
__invoke
C.
__wakeup
D.
__unset

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

20.

Which character do the error_reporting directive use to represent the logical operator NOT?

A.
/
B.
!
C.
~
D.
^

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The twidle (~) character is used to represent the logical operator NOT.


Feedback:

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