PHP Language | 20 Minute‐Test 6


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 is/are a PHP code editor?
i) Notepad
ii) Notepad++
iii) Adobe Dreamweaver
iv) PDT

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Any of the above editors can be used to type php code and run it.

2.

Which of the following PHP statements will output Hello World on the screen?
i) echo (“Hello World”);
ii) print (“Hello World”);
iii) printf (“Hello World”);
iv) sprintf (“Hello World”);

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

echo(), print() and printf() all three can be used to output a statement onto the screen. The sprintf() statement is functionally identical to printf() except that the output is assigned to a string rather than rendered to the browser.

3.

What will be the output of the following PHP code?

    <?php

    $num = 10;

    echo 'What is her age? \n She is $num years old';

    ?>

A.
What is her age? \n She is $num years old
B.
What is her age?
She is $num years old
C.
What is her age? She is 10 years old
D.
What is her age?
She is 10 years old

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

When a string is enclosed within single quotes both variables and escape sequences will not be interpreted when the string is parsed.

4.

What will happen in this function call?

    <?php

    function calc($price, $tax)

          {

        $total = $price + $tax;

    }

    $pricetag = 15;

    $taxtag = 3;

    calc($pricetag, $taxtag);

    ?>

A.
Call By Value
B.
Call By Reference
C.
Default Argument Value
D.
Type Hinting

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

When you pass an argument in the above manner or say we pass 15 and 3 directly, it is called passing by value or call by value.

5.

Which of the following PHP functions can be used to get the current memory usage?

A.
get_usage()
B.
get_peak_usage()
C.
get_memory_usage()
D.
get_memory_peak_usage()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

We can use the memory_get_usage() function, and to get the highest amount of memory used at any point, we can use the memory_get_peak_usage() function.

6.

What will be the output of the following php code?

    <?php

    $states = array("karnataka" => array

    ( "population" => "11,35,000", "captial" => "Bangalore"),

    "Tamil Nadu" => array( "population" => "17,90,000",

    "captial" => "Chennai") );

    echo $states["karnataka"]["population"];

    ?>

A.
karnataka 11,35,000
B.
11,35,000
C.
population 11,35,000
D.
karnataka population

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Treat states as a multidimensional array and accordingly traverse it to get the value.

7.

What will be the output of the following PHP code ?

<?php

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

$a2 = array("e" => "red","f" => "green", "g" => "blue");

$result = array_intersect($a1, $a2);

print_r($result);

?>

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The array_intersect() function compares the values of two (or more) arrays, and returns the matches.

8.

What will be the output of the following PHP code?

<?php

$cars = array("Volvo", "BMW", "Toyota", "Honda", "Mercedes", "Opel");

print_r(array_chunk($cars, 2));

?>

A.
Array ( [0] => Array ( [1] => Volvo [2] => BMW ) [1] => Array ( [1] => Toyota [2] => Honda ) [2] => Array ( [1] => Mercedes [2] => Opel ) )
B.
Array ( [1] => Array ( [1] => Volvo [2] => BMW ) [2] => Array ( [1] => Toyota [2] => Honda ) [3] => Array ( [1] => Mercedes [2] => Opel ) )
C.
Array ( [0] => Array ( [0] => Volvo [1] => Volvo ) [1] => Array ( [0] => BMW [1] => BMW ) [2] => Array ( [0] => Toyota [1] => Toyota ) )
D.
Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] => Honda ) [2] => Array ( [0] => Mercedes [1] => Opel ) )

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The array_chunk() function splits an array into chunks of new arrays.

9.

What will be the output of the following PHP code?

    <?php

    $fruits = array ("mango", "apple", "peach", "pear");

    $fruits = asort ($fruits);

    printr ($fruits);

    ?>

A.
Array ( [1] => apple [0] => mango [2] => peach [3] => pear )
B.
Array ( [0] => apple [1] => mango [2] => peach [3] => pear )
C.
Error
D.
Array ( [1] => apple [0] => mango [3] => peach [2] => pear )

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The function asort() sorts the array in ascending order, except that the key/value corresponding is maintained.

10.

The practice of creating objects based on predefined classes is often referred to as..

A.
class creation
B.
object creation
C.
object instantiation
D.
class instantiation

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

11.

PHP recognizes constructors by the name..

A.
classname()
B.
_construct()
C.
function _construct()
D.
function __construct()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

A double underscore followed by the construct keyword. Its syntax is function __construct ([ argument1, argument2,…..]) { Class Initialization code }

12.

Which one of the following is the right way to clone an object?

A.
_clone(targetObject);
B.
destinationObject = clone targetObject;
C.
destinationObject = _clone(targetObject);
D.
destinationObject = clone(targetObject);

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

You can clone an object by prefacing it with the clone keyword.

13.

Which version of PHP introduced E_STRICT Error level?

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Description for E_STRICT is PHP version portability suggestions

14.

Which version added the method getPrevious()?

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

15.

Which one of the following filter is used to filter several variables with the same or different filters?

A.
filter_var_array()
B.
filter_var()
C.
filter_input
D.
filter_input_array

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None

16.

[:alpha:] can also be specified as..

A.
[A-Za-z0-9]
B.
[A-za-z]
C.
[A-z]
D.
[a-z]

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

[:alpha:] is nothing but Lowercase and uppercase alphabetical characters.

17.

Say we have two compare two strings which of the following function/functions can you use?
i) strcmp()
ii) strcasecmp()
iii) strspn()
iv) strcspn()

A.
i) and ii)
B.
iii) and iv)
C.
None of the mentioned
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

All of the functions mentioned above can be used to compare strings in some or the other way.

18.

Which one of the following function is capable of reading a file into an array?

A.
file()
B.
arrfile()
C.
arr_file()
D.
file_arr()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None

19.

Which one of the following format parameter can be used to identify timezone?

A.
T
B.
N
C.
E
D.
I

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

When the format is E the timezone is identified and returned…example America/New_York.

20.

Which method is simply an object-oriented version of date()?

A.
DateTime::format()
B.
DateTime::modify()
C.
DateTime::setTime()
D.
DateTime::setDate()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The format() method is simply an object-oriented version of date(). It takes $dateFormat as an argument. $dateFormat is a string consisting of the same date formatting characters accepted by the procedural date() function.

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