Explore topic-wise MCQs in Php.

This section includes 54 Mcqs, each offering curated multiple-choice questions to sharpen your Php knowledge and support exam preparation. Choose a topic below to get started.

1.

What array will you get if you convert an object to an array?%!

A. An array with properties of that object as the array's elements
B. An array with properties of that array as the object's elements
C. An array with properties of that object as the Key elements
D. An array with keys of that object as the array's elements
Answer» B. An array with properties of that array as the object's elements
2.

What functions count elements in an array?1. count2. Sizeof3. Array_Count4. Count_array%!

A. Option 2 and 4
B. Option 1 and 2
C. Option 3 and 4
D. Option 1 and 4
Answer» C. Option 3 and 4
3.

What function computes the difference of arrays?%!

A. array_diff
B. diff_array
C. arrays_diff
D. diff_arrays
Answer» B. diff_array
4.

Which in-built function will add a value to the end of an array?%!

A. array_unshift()
B. into_array()
C. inend_array()
D. array_push()
Answer» E.
5.

*/*_What will be the output of the following PHP code ??

A. Lucy
B. Peter
C. Susan
D. Edmund
Answer» C. Susan
6.

*/*_What will be the output of the following PHP code ? "red", "b" => "green", "c" => "blue", "d" => "yellow");$result = array_flip($a1);print_r($result);?>?

A. Array ( [red] => red [green] => green [blue] => blue [yellow] => yellow )
B. Array ( [a] => a [b] => b [c] => c [d] => d )
C. Array ( [red] => a [green] => b [blue] => c [yellow] => d )
D. Array ( [a] => red [b] => green [c] => blue [d] => yellow )
Answer» D. Array ( [a] => red [b] => green [c] => blue [d] => yellow )
7.

*/*_What will be the output of the following PHP code??

A. Array ( [0] => peach )
B. Array ( [0] => apple [1] => mango [2] => peach )
C. Array ( [0] => apple [1] => mango )
D. Array ( [0] => peach [1] => pear [2] => orange )
Answer» E.
8.

*/*_What will be the output of the following PHP code??

A. Array ( [a] => blue [b] => yellow [c] => red [d] => green )
B. Array ( [0] => blue [1] => yellow [2] => red [3] => green )
C. Array ( [0] => red [1] => green [2] => blue [3] => yellow )
D. Array ( [a] => red [b] => green [c] => blue [d] => yellow )
Answer» E.
9.

*/*_What will be the output of the following PHP code??

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» B. Array ( [0] => green [1] => blue )
10.

*/*_Which function returns an array consisting of associative key/value pairs??

A. count()
B. array_count()
C. array_count_values()
D. count_values()
Answer» D. count_values()
11.

*/*_Which in-built function will add a value to the end of an array??

A. array_unshift()
B. into_array()
C. inend_array()
D. array_push()
Answer» E.
12.

*/*_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()
Answer» C. do_array()
13.

_ What will be the output of the following PHP code?$?

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 ) )
Answer» E.
14.

_ What will be the output of the following PHP code ?$?

A. Array ( [1] => Mumbai [0] => Beijing )
B. Array ( [0] => NYC [1] => London )
C. Array ( [1] => NYC [0] => London )
D. Array ( [0] => Mumbai [1] => Beijing )
Answer» E.
15.

_ What will be the output of the following PHP code ? "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» D. Array ( [Harry] => 21 [Ron] => 23 )
16.

_ What will be the output of the following PHP code?$?

A. Array ( [0] => A [1] => J [2] => Q [3] => K [4] => 2 [5] => 3 [6] => 4 [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )
B. Array ( [0] => A [1] => 2 [2] => J [3] => 3 [4] => Q [5] => 4 [6] => K [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )
C. Error
D. Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 7 [6] => 8 [7] => 9 [8] => 10 [9] => A [10] => J [11] => Q [12] => K )
Answer» B. Array ( [0] => A [1] => 2 [2] => J [3] => 3 [4] => Q [5] => 4 [6] => K [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )
17.

_ What will be the output of the following PHP code? "red", "b" => "green", "c" => "blue", "d" => "yellow");$a2 = array("e" => "red", "f" => "green", "g" => "blue", "h" => "orange");$a3 = array("i" => "orange");$a4 = array_combine($a2, $a3);$result = array_diff($a4, $a2);print_r($result);?>$?

A. Array ( [d] => yellow )
B. Array ( [i] => orange )
C. Array ( [h] => orange )
D. Array ( [d] => yellow [h] => orange )
Answer» B. Array ( [i] => orange )
18.

_ What will be the output of the following PHP code?"red", "b"=>"green", "c"=>"blue");echo array_shift($a);print_r ($a);?>$?

A. green
B. red
C. blue
D. none of the mentioned
Answer» C. blue
19.

_ What will be the output of the following PHP code?$?

A. 3
B. 4
C. 5
D. 6
Answer» E.
20.

_ 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()
Answer» C. do_array()
21.

_What will be the output of the following PHP code?"35", "Ben"=>"37", "Joe"=>"43");print_r(array_change_key_case($age, CASE_UPPER));?>$?

A. Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
B. Array ( [peter] => 35 [ben] => 37 [joe] => 43 )
C. Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )
D. Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )
Answer» D. Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )
22.

_What will be the output of the following PHP code ? "Jaguar", "b" => "Land Rover", "c" => "Audi", "d" => "Maseratti");echo array_search("Audi", $a);?>$?

A. a
B. b
C. c
D. d
Answer» D. d
23.

_What will be the output of the following PHP code?$?

A. Array ( [0] => LA [1] => Paris [2] => Paris )
B. Array ( [0] => NYC [1] => LA [2] => Paris)
C. Array ( [0] => NYC [1] => LA [2] => Paris [3] => Paris )
D. None of the mentioned
Answer» B. Array ( [0] => NYC [1] => LA [2] => Paris)
24.

_What will be the output of the following PHP code?$?

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 )
Answer» D. Array ( [0] => Picture10.jpg [1] => picture1.JPG [2] => picture20.jpg [3] => picture2.jpg )
25.

_What will be the output of the following PHP code?$?

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» B. Array ( [A] => 2 [Cat] => 2 [Dog] => 1 [Tiger] => 1 )
26.

_What will be the output of the following PHP code?$?

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» D. Array ( [0] => blue [1] => yellow )
27.

_Which function can be used to move the pointer to the previous array position?$?

A. last()
B. before()
C. prev()
D. previous()
Answer» D. previous()
28.

What will be the output of the following php code? 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
Answer» C. population 11,35,000
29.

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

A. Sam is the brother of Bob and Bob) $brother
B. Sam is the brother of Bob and Bob)
C. $brother
D. Error
Answer» E.
30.

What will be the output of the following PHP code ?

A. Array ( [0] => red [1] => green [2] => blue [3] => yellow )
B. Array ( [0] => blue [1] => yellow [2] => red [3] => green )
C. Array ( [0] => red [1] => green )
D. Array ( [0] => blue [1] => yellow )
Answer» B. Array ( [0] => blue [1] => yellow [2] => red [3] => green )
31.

What will be the output of the following PHP code ?

A. 024
B. 120
C. 010
D. 060
Answer» C. 010
32.

What will be the output of the following PHP code?

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 )
Answer» B. Array ( [0] => apple [1] => mango [2] => peach [3] => pear )
33.

What will be the output of the following PHP code?

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» E.
34.

What will be the output of the following PHP code?"red", "b"=>"green", "c"=>"blue", "d"=>"yellow");$a2 = array("e"=>"red", "f"=>"green", "g"=>"blue");$result = array_diff($a1, $a2);print_r($result);?>

A. Array ( [d] => yellow )
B. Array ( [c] => blue )
C. Array ( [a] => red )
D. Array ( [e] => yellow )
Answer» B. Array ( [c] => blue )
35.

What will be the output of the following PHP code?

A. orangebanana
B. appleorange
C. orangeorange
D. appleapple
Answer» B. appleorange
36.

Which of the following are correct ways of creating an array?1. state[0] = “karnataka”;2. $state[] = array(“karnataka”);3. $state[0] = “karnataka”;4. $state = array(“karnataka”);$

A. 3 and 4
B. 2 and 3
C. Only 1
D. 2, 3 and 4
Answer» B. 2 and 3
37.

What will be the output of the following PHP code ?

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» B. Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 )
38.

What will be the output of the following PHP code ? "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 )
Answer» B. Array ( [a] => red [b] => green [c] => blue [d] => yellow )
39.

What will be the output of the following PHP code?

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» C. Sam is the brother of Jack and Bob)
40.

What will be the output of the following PHP code?

A. mango
B. error
C. peach
D. 0
Answer» C. peach
41.

What will be the output of the following PHP code?

A. I like Volvo, Toyota and BMW
B. I like Volvo, BMW and Toyota
C. I like BMW, Volvo and Toyota
D. I like Toyota, BMW and Volvo
Answer» E.
42.

What will be the output of the following PHP code?

A. Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )
B. Array ( [A] => 2 [Cat] => 2 [Dog] => 1 )
C. Array ( [A] => 1 [Cat] => 1 [Dog] => 2 )
D. Array ( [A] => 2 [Cat] => 1 [Dog] => 1)
Answer» B. Array ( [A] => 2 [Cat] => 2 [Dog] => 1 )
43.

What will be the output of the following PHP code?

A. True
B. 1
C. False
D. 2
Answer» E.
44.

PHP’s numerically indexed array begin with position ______.#

A. 1
B. 2
C. 0
D. -1
Answer» D. -1
45.

What will the following script output?

A. 78
B. 19
C. NULL
D. 5
Answer» B. 19
46.

Array values are keyed by ______ values (called indexed arrays) or using ______ values (called associative arrays). Of course, these key methods can be combined as well.

A. Float, string
B. Positive number, negative number
C. Even number, string
D. String, Boolean
E. Integer, string
Answer» F.
47.

What will be the output of the following PHP code?

A. Array ( [0] => KA [1] => LA [2] => CA [3] => MA [4] => TA [5] => IA [6] => GA )
B. Array ( [0] => KA [2] => CA [4] => TA )
C. Array ( [1] => IA [3] => GA )
D. Array ( [1] => LA [3] => MA )
Answer» C. Array ( [1] => IA [3] => GA )
48.

What will be the output of the following PHP code?

A. 4hello2
B. 4
C. 2
D. 6
Answer» E.
49.

What will be the output of the following PHP code?

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

Assume you would like to sort an array in ascending order by value while preserving key associations. Which of the following PHP sorting functions would you use?

A. ksort()
B. asort()
C. krsort()
D. sort()
E. usort()
Answer» C. krsort()