PHP Language | 30 Minute‐Test 1


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.

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.

21.

When you use the $_POST variable to collect data, the data is visible to..

A.
none
B.
only you
C.
everyone
D.
selected few

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The POST method, data is invisible to others.

22.

Which function is used to verify whether a variable contains a value?

A.
header()
B.
footer()
C.
inset()
D.
isset()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The isset() function determines whether a variable has been assigned a value. Its prototype follows: boolean isset(mixed var [,mixed var [,…]])

23.

Since which version of PHP was the directive max_file_limit available.

A.
PHP 5.2.1
B.
PHP 5.2.2
C.
PHP 5.2.12
D.
PHP 5.2.21

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The max_file_limit directive sets an upper limit on the number of files which can be simultaneously uploaded.

24.

Which one of the following function is used to retrieve the MX records for the domain specified by hostname?

A.
getmx()
B.
retrieve_mx()
C.
getmxrr()
D.
retrieve_mxrr()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

25.

Which one of the following is the default PHP session name?

A.
PHPSESSID
B.
PHPSESID
C.
PHPSESSIONID
D.
PHPIDSESS

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

You can change this name by using the session.name directive.

26.

What will be the output of the following PHP code? Say your previous session username was nachi.

    unset($_SESSION['username']);

    printf("Username now set to: %s", $_SESSION['username']);

A.
Username now set to: nachi
B.
Username now set to: System
C.
Username now set to:
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

To delete the session variable ‘username’ we use the unset() function.

27.

The memory_limit is only applicable if ___ is enabled when you configure PHP. Fill in the blank.

A.
–enable-limit
B.
-enable-memory-limit
C.
–enable-memory-limit
D.
-memory-limit

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

This directive specifies, in megabytes, how much memory a script can use. Default value: 128M.

28.

What will be the output of the following PHP code?

    <?php

    $name = "What is your name?"

    if (preg_match("/name/"),$name)

    echo "My name is Will Pitt ";

    else

    echo "My name is not Will Pitt ";

    if (preg_match("/are/"))

    echo "I am great"

    else

    echo "I am not great";

    ?>

A.
My name is Will Pitt I am great
B.
My name is not Will Pitt I am great
C.
My name is Will Pitt I am not great
D.
My name is not Will Pitt I am not great

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The code uses preg_match to check for a keyword and replies based on whether it is true (1) or false (0).

29.

In which version of PHP was MySQL Native Driver(also known as mysqlnd) introduced?

A.
PHP 5.0
B.
PHP 5.1
C.
PHP 5.2
D.
PHP 5.3

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

PHP required that MySQL client library be installed on the server from which PHP was communicating with MySQL, whether the MySQL server also happened to reside locally or elsewhere. PHP 5.3 removes this problem by introducing MySQL Native Driver.

30.

Which of the methods are used to manage result sets using both associative and indexed arrays?

A.
get_array() and get_row()
B.
get_array() and get_column()
C.
fetch_array() and fetch_row()
D.
fetch_array() and fetch_column()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Their prototype is as follows-
calss mysqli_result{
mixed fetch_array ([int resulttype])
}
calss mysqli_result{
mixed fetch_row()
}

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