PHP Language | 10 Minute‐Test 2


Instruction

  • Total number of questions : 10.
  • Time alloted : 10 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
Submit your test now to view the Results and Statistics with answer explanation.