We have listed here some multiple choice questions with answers, which has asked by multiple companies like ABB, Aditi, Integra, BSNL, Lifetree, L& T Infotech etc.

You can prepare your job written and interview by using these sets of question from here.

1. What will be the output of the following PHP code?

<?php
$fname = array(“Peter”, “Ben”, “Joe”);
$age = array(“35”, “37”, “43”);
$c = array_combine($age, $fname);
print_r($c);
?>
a) Array ( Peter Ben Joe )
b) Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
c) Array ( 35 37 43 )
d) Array ( [35] => Peter [37] => Ben [43] => Joe )

Answer: d

2. What will be the output of the following PHP code?

<?php
$a=array(“A”,”Cat”,”Dog”,”A”,”Dog”);
$b=array(“A”,”A”,”Cat”,”A”,”Tiger”);
$c=array_combine($a,$b);
print_r(array_count_values($c));
?>
a) Array ( [A] => 5 [Cat] => 2 [Dog] => 2 [Tiger] => 1 )
b) Array ( [A] => 2 [Cat] => 2 [Dog] => 1 [Tiger] => 1 )
c) Array ( [A] => 6 [Cat] => 1 [Dog] => 2 [Tiger] => 1 )
d) Array ( [A] => 2 [Cat] => 1 [Dog] => 4 [Tiger] => 1 )

Answer: a

3. What will be the output of the following PHP code?

<?php
$names = array(“Sam”, “Bob”, “Jack”);
echo $names[0] . “is the brother of ” . $names[1] . ” and ” . $names[1] . “.”;
?>
a) Sam is the brother of Bob and Jack
b) Sam is the brother of Bob and Bob)
c) Sam is the brother of Jack and Bob)
d) Error

Answer: b

4. What will be the output of the following PHP code?

<?php
$names = array(“Sam”, “Bob”, “Jack”);
echo $names[0] . “is the brother of ” . $names[1] . ” and ” . $names[1] . “.”.$brother;
?>
a) Sam is the brother of Bob and Bob) $brother
b) Sam is the brother of Bob and Bob)
c) $brother
d) Error

Answer: d

5. What will be the output of the following PHP code ?

<?php
$age = array(“Harry” => “21”, “Ron” => “23”,”Malfoy” => “21”);
array_change_key_case($age, CASE_UPPER);
array_pop($age);
print_r($age);
?>
a) Array ( [Harry] => 21 [Ron] => 23 [Malfoy] => 21 )
b) Array ( [HARRY] => 21 [RON] => 23 [MALFOY] => 21 )
c) Array ( [HARRY] => 21 [RON] => 23 )
d) Array ( [Harry] => 21 [Ron] => 23 )

Answer: c

6. 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

Answer: b

7. What will be the output of the following PHP code ?

<?php
$people = array(“Peter”, “Susan”, “Edmund”, “Lucy”);
echo pos($people);
?>
a) Lucy
b) Peter
c) Susan
d) Edmund

Answer: b

8. 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 )

Answer: a

9. What will be the output of the following PHP code?

<?php
$cars = array(“Volvo”, “BMW”, “Toyota”);
echo “I like ” . $cars[0] . “, ” . $cars[1] . ” and ” . $cars[2] . “.”;
?>
a) I like Volvo BMW and Toyota)
b) I like Volvo, BMW and Toyota)
c) I like Volvo, BMW and Toyota
d) I like. Volvo.,. BMW. and) Toyota)

Answer: b

10. 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” )

Answer: b

11. What will be the output of the following PHP code?

<?php
$a1 = array(“red”, “green”);
$a2 = array(“blue”, “yellow”);
print_r(array_merge($a1, $a2));
?>
a) Array ( [0] => red [1] => green)
b) Array ( [0] => blue [1] => yellow [2] => red [3] => green )
c) Array ( [0] => red [1] => green [2] => blue [3] => yellow )
d) Array ( [0] => blue [1] => yellow )

Answer: c

12. What will be the output of the following PHP code?

<?php
$a = array(“red”, “green”, “blue”);
array_pop($a);
print_r($a);
?>
a) Array ( [0] => red [1] => green )
b) Array ( [0] => green [1] => blue )
c) Array ( [0] => red [1] => blue )
d) Array ( [0] => blue [1] => blue )

Answer: a

13. Which of the functions is used to sort an array in descending order?
a) sort()
b) asort()
c) rsort()
d) dsort()

Answer: c

14. Say in the above question you need to get the array sorted in the manner we humans would have done it i.e picture1 then picture2 etc.. Which of the following function should be used?
a) dsort()
b) casesort()
c) natcasesort()
d) naturalsort()

Answer: c

15. What will be the output of the following PHP code?

<?php
$fruits = array (“apple”, “mango”, “peach”, “pear”,
“orange”);
$subset = array_splice ($fruits, 2);
print_r ($fruits);
?>
a) Error
b) Array ( [0] => apple [1] => mango [2] => peach )
c) Array ( [0] => apple [1] => mango )
d) Array ( [0] => pear [1] => orange )

Answer: c

16. The practice of separating the user from the true inner workings of an application through well-known interfaces is known as _________
a) Polymorphism
b) Inheritance
c) Encapsulation
d) Abstraction

Answer: c

17. Which one of the following can be used to instantiate an object in PHP assuming class name to be Foo?
a) $obj = new $foo;
b) $obj = new foo;
c) $obj = new foo ();
d) obj = new foo ();

Answer: c

18. Which one of the following is the right way to call a class constant, given that the class is mathFunction?
a) echo PI;
b) echo mathFunction->PI;
c) echo mathFunction::PI;
d) echo mathFunction=PI;

Answer: c

19. Which method scope prevents a method from being overridden by a subclass?
a) Abstract
b) Protected
c) Final
d) Static

Answer: c

20. PHP recognizes constructors by the name_________
a) classname()
b) _construct()
c) function _construct()
d) function __construct()

Answer: d

21. Which one of the following functions is used to determine whether a class exists?
a) exist()
b) exist_class()
c) class_exist()
d) __exist()

Answer: c

22. Which one of the following keyword is used to inherit our subclass into a superclass?
a) extends
b) implements
c) inherit
d) include

Answer: a

23. Which keyword is used to refer to properties or methods within the class itself?
a) private
b) public
c) protected
d) $this

Answer: d

24. Which version of PHP introduced the advanced concepts of OOP?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6

Answer: b

25. Which of the following is/are true for an abstract class?
i) A class is declared abstract by prefacing the definition with the word abstract.
ii) A class is declared abstract by using the keyword implements.
iii) It is a class that really isn’t supposed to ever be instantiated but instead serves as a base class.
iv) Attempting to instantiate an abstract class result in an error.
a) Only ii)
b) All of the mentioned
c) ii) and iv)
d) ii), iii) and iv)

Answer: a