PHP Language | 20 Minute‐Test 3


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.

What will be the output of the following php code?

    <?php

    $num  = 1;

    $num1 = 2;

    print $num + $num1;

    ?>

A.
3
B.
1+2
C.
Error
D.
12

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The numbers inside the double quotes are considered as integers and not string, therefore the value 3 is printed and not 1+2.

2.

What will be the output of the following code?

    <?php

    function track() {

    static $count = 0;

    $count++;

    echo $count;

    }

    track();

    track();

    track();

    ?>

A.
123
B.
111
C.
000
D.
011

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Because $count is static, it retains its previous value each time the function is executed.

3.

What is the value of $a and $b after the function call?

    <?php

    function doSomething( &$arg ) {

        $return = $arg;

        $arg += 1;

        return $return;

          }

    $a = 3;

    $b = doSomething( $a );

    ?>

A.
a is 3 and b is 4.
B.
a is 4 and b is 3.
C.
Both are 3.
D.
Both are 4.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

$a is 4 and $b is 3. The former because $arg is passed by reference, the latter because the return value of the function is a copy of the initial value of the argument.

4.

A function in PHP which starts with __ (double underscore) is know as.

A.
Magic Function
B.
Inbuilt Function
C.
Default Function
D.
User Defined Function

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

PHP functions that start with a double underscore – a “__” – are called magic functions in PHP. They are functions that are always defined inside classes, and are not stand-alone functions.

5.

What will be the output of the following PHP code?

    <?php

    echo ucwords("i love my country");

    ?>

A.
I love my country
B.
i love my Country
C.
I love my Country
D.
I Love My Country

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The ucwords() function converts the first character of each word in a string to uppercase.

6.

What will be the output of the following PHP code?

    <?php

    $fruits = array ("apple", "orange", array ("pear", "mango"),

    "banana");

    echo (count($fruits, 1));

    ?>

A.
3
B.
4
C.
5
D.
6

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The array entity holding pear and mango is counted as an item, just as its contents are.

7.

What will be the output of the following PHP code ?

<?php

$number = range(0, 5);

print_r ($number);

?>

A.
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )
B.
Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 )
C.
Array ( [0] => 5 [1] => 5 [2] => 5 [3] => 5 [4] => 5 [5] => 5 )
D.
Array ( [0] => 0 [5] => 5 )

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

the range() function creates an array containing a range of elements.

8.

What will be the output of the following PHP code?

<?php

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

echo array_shift($a);

print_r ($a);

?>

A.
green
B.
red
C.
blue
D.
none of the above

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The array_shift() function removes the first element from an array, and returns the value of the removed element.

9.

What will be the output of the following PHP code?

    <?php

    $number = array ("4", "hello", 2);

    echo (array_sum ($number));

    ?>

A.
4hello2
B.
4
C.
2
D.
6

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The array_sum() function add all the values of the input array together, returning the final sum. If a string datatype is found, it’ll be ignored.

10.

Which of the following is/are the right way to declare a method?
i) function functionName() { function body }
ii) scope function functionName() { function body }
iii) method methodName() { method body }
iv) scope method methodName() { method body }

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

In case of public methods, you can forgo explicitly declaring the scope and just declare the method like you would a function.

11.

Which keyword is used to refer to properties or methods within the class itself?

A.
private
B.
public
C.
protected
D.
$this

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

12.

Which feature allows us to call more than one method or function of the class in single instruction?

A.
Typecasting
B.
Method Including
C.
Method adding
D.
Method chaining

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Following is a basic example of method chaining in php: $a = new Order(); $a->CreateOrder()->sendOrderEmail()->createShipment();

13.

Which logging option’s description is, if an error occurs when writing to the syslog, send output to the system console?

A.
LOG_CONS
B.
LOG_NDELAY
C.
LOG_ODELAY
D.
LOG_PERROR

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

14.

Which of the following is/are not an exception?
i) BadFunctionCallException
ii) BadMethodCallException
iii) LogicException
iv) DomainException

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

15.

What will be the output of the following PHP code?

    <?php

    $value = 'car';

    $result = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

    ?>

A.
FALSE
B.
TRUE
C.
NULL
D.
ERROR

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

There is an undocumented filter flag for FILTER_VALIDATE_BOOLEAN. The documentation implies that it will return NULL if the value doesn’t match the allowed true/false values. However this doesn’t happen unless you give it the FILTER_NULL_ON_FAILURE flag.

16.

Which of the following would be a potential match for the Perl-based regular expression /fo{2,4}/ ?
i) fol
ii) fool
iii) fooool
iv) fooooool

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

This matches f followed by two to four occurrences of o.

17.

Which one of the following functions finds the last occurrence of a string, returning its numerical position?

A.
strlastpos()
B.
strpos()
C.
strlast()
D.
strrpos()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None

18.

Which function is useful when you want to output the executed command’s result?

A.
out_cmm()
B.
out_system()
C.
cmm()
D.
system()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None

19.

Say you want to calculate the date 45 days from the present date which one of the following statement will you use?

A.
totime(“+45”)
B.
totime(“+45 days”)
C.
strtotime(“+45 days”)
D.
strtotime(“-45 days”)

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The strtotime() function and GNU date syntax is used to calculating the date x days from the present date.

20.

Which of the following statements can be used to add two months to the existing date?

A.
$date->modify(‘+2 months’
B.
$date = modify(‘+2 months’);
C.
$date = modify(‘2+ months’);
D.
$date->modify(‘2+ months’);

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

To change the date stored by a DateTime object after it has been created, you use DateTime::modify() with a natural language expression.

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