PHP Language | 20 Minute‐Test 5


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.

PHP files have a default file extension of..

A.
.html
B.
.xml
C.
.php
D.
.ph

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

2.

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.

3.

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.

4.

Type Hinting was introduced in which version of PHP?

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Type hinting gives you the ability to force parameters to be objects of certain class or to be arrays. PHP 5 introduced this feature.

5.

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

6.

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.

7.

What will be the output of the following PHP code ?

<?php

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

$result = array_flip($a1);

print_r($result);

?>

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The array_flip() function flips/exchanges all keys with their associated values in an array.

8.

What will be the output of the following PHP code?

<?php

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

print_r(array_change_key_case($age, CASE_UPPER));

?>

A.
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
B.
Array ( [peter] => 35 [ben] => 37 [joe] => 43 )
C.
Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )
D.
Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The array_change_key_case() function changes all keys in an array to lowercase or uppercase.

9.

Which of the functions is used to sort an array in descending order?

A.
sort()
B.
asort()
C.
rsort()
D.
dsort()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

sort() function is used to sort in ascending order where as rsort() meaning reverse sort is used for sorting in descending order.

10.

Which of the following term originates from the Greek language that means “having multiple forms,” defines OOP’s ability to redefine, a class’s characteristics?

A.
Abstraction
B.
Polymorphism
C.
Inheritance
D.
Differential

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

11.

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.

12.

Which version of PHP introduced the advanced concepts of OOP?

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

13.

What is the description of Error level E_ERROR?

A.
Fatal run-time error
B.
Near-fatal error
C.
Compile-time error
D.
Fatal Compile-time error

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

14.

How many methods are available for the exception class?

A.
5
B.
6
C.
7
D.
8

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The seven methods are: getCode(), getFile(), getLine(), getMessage(), getPrevious(), getTrace(), getTraceAsString()

15.

How many types of filtering are present in PHP?

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

There are two main types of filtering: validation and sanitization.

16.

Which one of the following regular expression matches any string containing zero or one p?

A.
p+
B.
p*
C.
P?
D.
p#

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

17.

What will be the output of the following PHP code?

    <?php

    $foods = array("pasta", "steak", "fish", "potatoes");

    $food = preg_grep("/^s/", $foods);

    print_r($food);

    ?>

A.
Array ( [0] => pasta [1] => steak [2] => fish [3] => potatoes )
B.
Array ( [3] => potatoes )
C.
Array ( [1] => steak )
D.
Array ( [0] => potatoes )

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

This function is used to search an array for foods beginning with s.

18.

Which one of the following PHP function is used to determine a file’s last access time?

A.
fileltime()
B.
filectime()
C.
fileatime()
D.
filetime()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The fileatime() function returns a file’s last access time in Unix timestamp format or FALSE on error.

19.

The date() function returns ___ representation of the current date and/or time.

A.
Integer
B.
String
C.
Boolean
D.
Float

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The prototype of this function is: string date(string format [, int timestamp])

20.

How many constants does the DateTime class have?

A.
8
B.
9
C.
10
D.
11

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The DateTime class has 11 constants, no static properties or methods.

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