PHP Language | 10 Minute‐Test 4


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.

Which of the following must be installed on your computer so as to run PHP script?
i) Adobe Dreamweaver
ii) PHP
iii) Apache
iv) IIS

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

To run PHP code you need to have PHP and a web server, both IIS and Apache are web servers.You can choose either one according to your platform.

2.

What will be the output of the following PHP code?

    <?php

    $color = "maroon";

    $var = $color[2];

    echo "$var";

    ?>

A.
a
B.
Error
C.
$var
D.
r

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

PHP treats strings in the same fashion as arrays, allowing for specific characters to be accessed via array offset notation.

3.

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.

4.

What will be the output of the following PHP code?

    <?php

    function calc($price, $tax="")

    {

        $total = $price + ($price * $tax);

        echo "$total";

    }

    calc(42);

    ?>

A.
Error
B.
0
C.
42
D.
84

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

You can designate certain arguments as optional by placing them at the end of the list and assigning them a default value of nothing.

5.

Which of the following PHP functions can be used for generating unique id’s?

A.
uniqueid()
B.
id()
C.
md5()
D.
mdid()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Many people use the md5() function for this, even though it’s not exactly meant for this purpose. uniqueid() is the function that is to be used.

6.

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

7.

What will be the output of the following PHP code ?

<?php

$a = array(12, 5, 2);

echo(array_product($a));

?>

A.
024
B.
120
C.
010
D.
060

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The array_product() function calculates and returns the product of an array.

8.

What will be the output of the following PHP code?

<?php

$fname = array("Peter", "Ben", "Joe");

$age = array("35", "37", "43");

$c = array_combine($fname, $age);

print_r($c);

?>

A.
Array ( Peter Ben Joe )
B.
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
C.
Array ( 35 37 43 )
D.
Array ( “[Peter] => 35” “[Ben] => 37” “[Joe] => 43” )

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The array_combine() function creates an array by using the elements from one “keys” array and one “values” array.

9.

What will be the output of the following PHP code?

    <?php

    $arr = array ("picture1.JPG", "picture2.jpg",

    "Picture10.jpg", "picture20.jpg");

    sort($arr);

    print_r($arr);

    ?>

A.
Array ( [0] => picture1.JPG [1] => Picture10.jpg [2] => picture2.jpg [3] => picture20.jpg )
B.
Array ( [0] => picture1.JPG [1] => picture2.jpg [2] => Picture10.jpg [3] => picture20.jpg )
C.
Array ( [0] => Picture10.jpg [1] => picture1.JPG [2] => picture2.jpg [3] => picture20.jpg )
D.
Array ( [0] => Picture10.jpg [1] => picture1.JPG [2] => picture20.jpg [3] => picture2.jpg )

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

While sorting each character is compared with the others and sorted using ascii values therefore we the sorted array to be like option c.

10.

Which one of the following property scopes is not supported by PHP?

A.
friendly
B.
final
C.
public
D.
static
Submit your test now to view the Results and Statistics with answer explanation.