PHP Language | 20 Minute‐Test 2


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.

What will be the output of the following php code?

    <?php

    $num  = 1;

    $num1 = 2;

    print $num . "+". $num1;

    ?>

A.
3
B.
1+2
C.
1.+.2
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

.(dot) is used to combine two parts of the statement. Example ( $num . “Hello World” ) will output 1Hello World.

2.

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.

3.

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 : .

4.

What will be the output of the following PHP code?

    <?php

    $op2 = "blabla";

    function foo($op1)

    {

        echo $op1;

        echo $op2;

    }

    foo("hello");

    ?>

A.
helloblabla
B.
Error
C.
hello
D.
helloblablablabla

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

If u want to put some variables in function that was not passed by it, you must use “global”. Inside the function type global $op2.

5.

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.
wo
rld
D.
World

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

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

6.

Which function can be used to move the pointer to the previous array position?

A.
last()
B.
before()
C.
prev()
D.
previous()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

7.

What will be the output of the following PHP code ?

<?php

$array = array("red", "green");

array_push($array, "blue", "yellow");

print_r($array);

?>

A.
Array ( [0] => red [1] => green [2] => blue [3] => yellow )
B.
Array ( [0] => blue [1] => yellow [2] => red [3] => green )
C.
Array ( [0] => red [1] => green )
D.
Array ( [0] => blue [1] => yellow )

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The array_push() function inserts one or more elements to the end of an array.

8.

What will be the output of the following PHP code?

<?php

$a1 = array("red", "green");

$a2 = array("blue", "yellow");

print_r(array_merge($a1, $a2));

?>

A.
Array ( [0] => red [1] => green)
B.
Array ( [0] => blue [1] => yellow [2] => red [3] => green )
C.
Array ( [0] => red [1] => green [2] => blue [3] => yellow )
D.
Array ( [0] => blue [1] => yellow )

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The array_merge() function merges one or more arrays into one array.

9.

What will be the output of the following PHP code?

    <?php

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

    $subset = array_splice ($fruits, 2);

    print_r ($fruits);

    ?>

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The array_splice() function removes all elements of an array found within a specified range

10.

Which one of the following is the right way to invoke a method?

A.
$object->methodName();
B.
object->methodName();
C.
object::methodName();
D.
$object::methodName();

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

11.

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.

12.

Which method is used to tweak an object’s cloning behavior?

A.
clone()
B.
__clone()
C.
_clone
D.
object_clone()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

13.

Which function initializes the constants necessary for using the openlog(), clodelog(), and syslog() functions?

A.
define_variable()
B.
define_log_variable()
C.
log_variable()
D.
define_syslog_variable()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

If you’re running PHP version 5.2.X or older, you need to execute this function before using any of the following logging functions.

14.

How many predefined exceptions does SPL provide access to?

A.
13
B.
14
C.
15
D.
16

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

15.

Which one of the following filter checks if variable of specified type exists?

A.
filter_has_var
B.
filter_var
C.
filter_id
D.
filter_var_array

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None

16.

What will be the output of the following PHP code?

    <?php

    $text = "this is\tsome text that\nwe might like to parse.";

    print_r(split("[\n\t]",$text));

    ?>

A.
this is some text that we might like to parse.
B.
Array ( [0] => some text that [1] => we might like to parse. )
C.
Array ( [0] => this is [1] => some text that [2] => we might like to parse. )
D.
[0] => this is [1] => some text that [2] => we might like to parse.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The split() function divides a string into various elements, with the boundaries of each element based on the occurrence of a defined pattern within the string.

17.

What will be the output of the following PHP code?

    <?php

    $author = "[email protected]";

    $author = str_replace("a","@",$author);

    echo "Contact the author of this article at $author.";

    ?>

A.
Contact the author of this article at [email protected]@mple.com
B.
[email protected] the @uthor of this @rticle @t [email protected]@[email protected]
C.
Contact the author of this article at [email protected]@[email protected]
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The str_replace() function case sensitively replaces all instances of a string with another.

18.

Which function sets the file filename’s last-modified and last-accessed times?

A.
sets()
B.
set()
C.
touch()
D.
touched()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Its prototype is int touch(string filename [, int time [, int atime]]). It returns TRUE on success or FALSE on error.

19.

What will be the output of the following PHP code? If say date is 22/06/2013.

    <?php

    printf( date("t") )

    ?>

A.
30
B.
22
C.
JUNE
D.
2013

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The t parameter is used to determine the number of days in the current month.

20.

Among the four PHP DateTimeZone classes given below how many are nonstatic?
i) _construct()
ii) getName()
iii) getOffset()
iv) getTransitions()

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

All of the given methods are non static.

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