PHP Language | 10 Minute‐Test 3


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 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
Submit your test now to view the Results and Statistics with answer explanation.