PHP Language | 30 Minute‐Test 5


Instruction

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

could potentially wreak havoc on a page.

21.

What will be the value of the variable $input in the following PHP code?

    <?php

    $input = "Swapna<td>Lawrence</td>you are really<i>pretty</i>!";

    $input = strip_tags($input,"<i></i>");

    ?>

A.
Swapna Lawrence you are really pretty!
B.
Swapna <td>Lawrence</td> you are really<i>pretty</i>!
C.
Swapna <td>Lawrence</td> you are really pretty!
D.
Swapna Lawrence you are really<i>pretty</i>!

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Italic tags might be allowable, but table tags

22.

Which function is used to split a string into a series of substrings, with each string boundary is determined by a specific separator?

A.
break()
B.
divide()
C.
explode()
D.
md5()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Although they are similar function, you should use explode() instead of split().In fact split() function has been deprecated altogether.

23.

Which superglobal stores a variety of information pertinent to a file uploaded to the server via a PHP script?

A.
$_FILE Array
B.
$_FILEs Array
C.
$_FILES_UPLOADED Array
D.
$_FILE_UPLOADED Array

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None

24.

Which one of the following function is used to send a e-mail using PHP script?

A.
mail_send()
B.
send_mail()
C.
mailrr()
D.
mail()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

mail(string to, string subject, string message,) using this you can send any mail.

25.

What is the default number of seconds that cached session pages are made available before the new pages are created?

A.
360
B.
180
C.
3600
D.
1800

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The directive which determines this is session.cache_expire.

26.

Which function is used to transform PHP’s session-handler behavior into that defined by your custom handler?

A.
session_set_save()
B.
session_set_save_handler()
C.
Session_handler()
D.
session_save_handler()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None

27.

Which directive should we disable to obscure the fact that PHP is being used on our server?

A.
show_php
B.
expose_php
C.
print_php
D.
info_php

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Using the expose_php directive we can prevent PHP version details from being appended on our web server signature. When expose_php is disabled, the server signature will look like: Apache/2.2.11 (Ubuntu) Server.

28.

What will be the output of the following PHP code?

    <?php

    $line = "You like dogs. I hate dogs. We should marry."

    $sen = preg_split('/\./', $line);

    print_r($sen);

    ?>

A.
You like dogs. I hate dogs. We should marry.
B.
Array([0]=>You like dogs. I hate dogs. We should marry.)
C.
Array([0]=>You like dogs. [1]=>I hate dogs. [2]=>We should marry.)
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

We use a ‘.’ period to split the data, therefor giving each sentence it’s own array entry.

29.

Which one of the following methods can be used to diagnose and display information about a MySQL connection error?

A.
connect_errno()
B.
connect_error()
C.
mysqli_connect_errno()
D.
mysqli_connect_error()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The mysqli extension includes a few features that can be used to capture error messages or alternatively you can use exceptions.

30.

Which one of the following methods is used to recuperating prepared statements resources?

A.
end()
B.
finish()
C.
final()
D.
close()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Once you’ve finished using a prepared statement, the resources it requires can be recuperated with the close() method.

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