Practice high-yield Programming & Software Development MCQs on Arrays — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
PHP’s numerically indexed array begin with position ______.
Correct Answer: Option C — 0
Detailed Academic Explanation:
Like many programming languages, the first element of an array has an index value of 0.
💡Key Conceptual Anchor:Arrays
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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”);
Correct Answer: Option A — 3 and 4
Detailed Academic Explanation:
A variable name should start with $ symbol which is not present in i) and you need not put the square brackets when you use the array() constructor.
💡Key Conceptual Anchor:Arrays
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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" ] ; ?>
Correct Answer: Option B — 11,35,000
Detailed Academic Explanation:
Treat states as a multidimensional array and accordingly traverse it to get the value.
💡Key Conceptual Anchor:Arrays
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function will return true if a variable is an array or false if it is not?
Correct Answer: Option B — is_array()
Detailed Academic Explanation:
A built-in function, is_array(), is available for testing an array. Its prototype follows: boolean is_array(mixed variable).
💡Key Conceptual Anchor:Arrays
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which in-built function will add a value to the end of an array?
Correct Answer: Option D — array_push()
Detailed Academic Explanation:
array_push adds a value to the end of an array, returning the total count of elementsin the array after the new value has been added.
💡Key Conceptual Anchor:Arrays
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $state = array ( "Karnataka" , "Goa" , "Tamil Nadu" , "Andhra Pradesh" ) ; echo (array_search ( "Tamil Nadu" , $state ) ) ; ?>
Correct Answer: Option D — 2
Detailed Academic Explanation:
The array_search() function searches an array for a specified value, returning its key if located and FALSE otherwise.
💡Key Conceptual Anchor:Arrays
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $fruits = array ( "apple" , "orange" , "banana" ) ; echo (next( $fruits )) ; echo (next( $fruits )) ; ?>
Correct Answer: Option A — orangebanana
Detailed Academic Explanation:
The next() function returns the array value residing at the position immediately following that of the current array pointer.
💡Key Conceptual Anchor:Arrays
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $fruits = array ( "apple" , "orange", array ( "pear" , "mango" ) , "banana" ) ; echo (count( $fruits, 1 )) ; ?>
Correct Answer: Option D — 6
Detailed Academic Explanation:
The array entity holding pear and mango is counted as an item, just as its contents are.
💡Key Conceptual Anchor:Arrays
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $cars = array( "Volvo" , "BMW" , "Toyota" ) ; echo "I like " . $cars [ 2 ] . ", " . $cars [ 1 ] . " and " . $cars [ 0 ] . "." ; ?>
Correct Answer: Option D — I like Toyota, BMW and Volvo
Detailed Academic Explanation:
The order of elements defined.
💡Key Conceptual Anchor:Arrays
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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 ) ; ?>
Correct Answer: Option D — Array ( [35] => Peter [37] => Ben [43] => Joe )
Detailed Academic Explanation:
Here “keys” array is $age and “values” array is $fname.
💡Key Conceptual Anchor:Arrays
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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 )) ; ?>
The array_diff() function compares the values of two (or more) arrays, and returns the differences.
💡Key Conceptual Anchor:Arrays
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $a1 = array( "red" , "green" ) ; $a2 = array( "blue" , "yellow" ) ; $a3 = array_merge( $a1, $a2 ) ; $a4 = array( "a" , "b" , "c" , "d" ) ; $a = array_combine( $a4, $a3 ) ; print_r( $a ) ; ?>
Correct Answer: Option D — Array ( [a] => red [b] => green [c] => blue [d] => yellow )
Detailed Academic Explanation:
Basic combined application of array_combine() and array_merge().
💡Key Conceptual Anchor:Arrays
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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 ] . "." ; ?>
Correct Answer: Option B — Sam is the brother of Bob and Bob)
Detailed Academic Explanation:
Simple definition of array and using it in a string. We have used $names[1] twice and hence Bob appears twice.
💡Key Conceptual Anchor:Arrays
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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; ?>
Correct Answer: Option D — Error
Detailed Academic Explanation:
$brother undeclared.
💡Key Conceptual Anchor:Arrays
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $place = array( "NYC" , "LA" , "Paris" ) ; array_pop( $place ) ; $place1 = array( "Paris" ) ; $place = array_merge( $place, $place1 ) ; print_r( $place ) ; ?>
Correct Answer: Option A — Array ( [0] => LA [1] => Paris [2] => Paris )
Detailed Academic Explanation:
array_merge() and array_pop() yields that result.
💡Key Conceptual Anchor:Arrays
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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 ); ?>
The array_replace() function replaces the values of the first array with the values from following arrays
💡Key Conceptual Anchor:Arrays
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code ? <?php $people = array( "Peter" , "Susan" , "Edmund" , "Lucy" ) ; echo pos( $people ) ; ?>
Correct Answer: Option B — Peter
Detailed Academic Explanation:
The pos() function returns the value of the current element in an array, and since no operation has been done, the current element is the first element.
💡Key Conceptual Anchor:Arrays
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code ? <?php $number = range( 0 , 5 ) ; print_r ( $number ) ; ?>
The range() function creates an array containing a range of elements.
💡Key Conceptual Anchor:Arrays
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code ? <?php $array = array( "red" , "green" ) ; array_push( $array, "blue" , "yellow" ) ; print_r( $array ) ; ?>
Correct Answer: Option A — Array ( [0] => red [1] => green [2] => blue [3] => yellow )
Detailed Academic Explanation:
The array_push() function inserts one or more elements to the end of an array.
💡Key Conceptual Anchor:Arrays
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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 )) ; ?>
The array_diff() function compares the values of two (or more) arrays, and returns the differences.
💡Key Conceptual Anchor:Arrays
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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 )) ; ?>
Correct Answer: Option C — Array ( [0] => red [1] => green [2] => blue [3] => yellow )
Detailed Academic Explanation:
The array_merge() function merges one or more arrays into one array.
💡Key Conceptual Anchor:Arrays
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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 ) ; ?>
Correct Answer: Option B — red
Detailed Academic Explanation:
The array_shift() function removes the first element from an array, and returns the value of the removed element.
💡Key Conceptual Anchor:Arrays
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $a = array( "red" , "green" , "blue" ) ; array_pop( $a ) ; print_r( $a ) ; ?>
Correct Answer: Option A — Array ( [0] => red [1] => green )
Detailed Academic Explanation:
The array_pop() function deletes the last element of an array.
💡Key Conceptual Anchor:Arrays
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $fruits = array ( "mango" , "apple" , "pear" , "peach" ) ; $fruits = array_flip( $fruits ) ; echo ( $fruits [ 0 ]) ; ?>
Correct Answer: Option B — error
Detailed Academic Explanation:
As we are flipping the values, $fruits[“mango”] = 0, $fruits[“apple”] = 1 and so on.
💡Key Conceptual Anchor:Arrays
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $fruits = array ( "mango" , "apple" , "peach" , "pear" ) ; $fruits = asort ( $fruits ) ; printr ( $fruits ) ; ?>
Correct Answer: Option A — Array ( [1] => apple [0] => mango [2] => peach [3] => pear )
Detailed Academic Explanation:
The function asort() sorts the array in ascending order, except that the key/value corresponding is maintained.
💡Key Conceptual Anchor:Arrays
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $arr = array ( "picture1.JPG" , "picture2.jpg" , "Picture10.jpg" , "picture20.jpg" ) ; sort( $arr ) ; print_r( $arr ) ; ?>
The array_slice() function returns a section of an array based on a starting and ending offset value.
💡Key Conceptual Anchor:Arrays
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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 ) ; ?>
Correct Answer: Option C — Array ( [0] => apple [1] => mango )
Detailed Academic Explanation:
The array_splice() function removes all elements of an array found within a specified range.
💡Key Conceptual Anchor:Arrays
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $number = array ( "4" , "hello" , 2 ) ; echo (array_sum ( $number )) ; ?>
Correct Answer: Option D — 6
Detailed Academic 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.
💡Key Conceptual Anchor:Arrays
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $array1 = array ( "KA" , "LA" , "CA" , "MA" , "TA" ) ; $array2 = array ( "KA" , "IA" , "CA" , "GA" , "TA" ) ; $inter = array_intersect ( $array1, $array2 ) ; print_r ( $inter ) ; ?>
Correct Answer: Option B — Array ( [0] => KA [2] => CA [4] => TA )
Detailed Academic Explanation:
The array_intersect() function returns a key preserved array consisting only of those values present in the first array that are also present in each of the other input arrays.
💡Key Conceptual Anchor:Arrays
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.