PHP Language | 20 Minute‐Test 7


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.

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

PHP supports five class property scopes: public, private, protected, final and static.

11.

Which version of PHP introduced the instanceof keyword?

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Using instanceof keyword we can determine whether an object is an instance of a class. $manager = new Employee() … if ($manager instanceof Employee) echo “True”;

12.

The class from which the child class inherits is called..
i) Child class
ii) Parent class
iii) Super class
iv) Base class

A.
Only i)
B.
ii), iii) and iv)
C.
Only iii)
D.
ii) and iv)

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

13.

Which character do the error_reporting directive use to represent the logical operator NOT?

A.
/
B.
!
C.
~
D.
^

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The twidle (~) character is used to represent the logical operator NOT.

14.

Which of the following statements invoke the exception class?

A.
throws new Exception();
B.
throw new Exception();
C.
new Exception();
D.
new throws Exception();

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None

15.

What will be the output of the following PHP code?

    <?php

    $num = "123";

    if (!filter_var($num, FILTER_VALIDATE_INT))

        echo("Integer is not valid");

    else

        echo("Integer is valid");

    ?>

A.
No output is returned
B.
Integer is not valid
C.
Integer is valid
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

filter_var() – Filters a single variable with a specified filter.

16.

How many functions does PHP offer for searching strings using POSIX style regular expression?

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

ereg(), ereg_replace(), eregi(), eregi_replace(), split(), spliti(), and sql_regcase() are the functions offered.

17.

Which one of the following functions will convert a string to all uppercase?

A.
strtoupper()
B.
uppercase()
C.
str_uppercase()
D.
struppercase()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Its prototype follows string strtoupper(string str).

18.

Which one of the following function is capable of reading a file into a string variable?

A.
file_contents()
B.
file_get_contents()
C.
file_content()
D.
file_get_content()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None

19.

If the format is F then which one of the following will be returned?

A.
Complete text representation of month
B.
Day of month, with leading zero
C.
Daylight saving time
D.
Day of month, without zeros

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Day of month, with leading zero is represented by D; Daylight saving time by I; Day of month, without zeros by j.

20.

Which of the following is the right way to use the DateTime class?

A.
$date = get_Class(DateTime);
B.
$date = class DateTime;
C.
$date = new DateTime();
D.
$date = new class DateTime();

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The way you use the DateTime class is like any other class: instantiate an object, and store it in a variable.

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