PHP Multiple Choice Questions & Answers (MCQs) focuses on “Array”.

Q 1. PHP’s numerically indexed array begin with position ___________
A. 0
B. 1
C. 2
D. -1

Show Answer Answer:-A. 0
Explanation Like all the other programming languages, the first element of an array always starts with ‘0’.

Q 2. Which of the following are correct ways of creating an array?

i) state[0] = "karnataka";
ii) $state[] = array("karnataka");
iii) $state[0] = "karnataka";
iv)  $state = array("karnataka");

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

Show Answer Answer:-C. iii) and iv)
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.

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

<?php

$states = array(“Karnataka” => array

(“population” => “11,35,000”, “capital” => “Bangalore”),

“Tamil Nadu” => array( “population” => “17,90,000”,

“capital” => “Chennai”) );

echo $states[“Karnataka”][“population”];

?>

A. 11,35,000
B. Karnataka 11,35,000
C. population 11,35,000
D. Karnataka population

Show Answer Answer:-A. 11,35,000
Explanation In the following PHP code, the variable states are treated as a multidimensional array and accordingly traverse it to get the value of ‘Karnataka’s population’.

Q 4. Which of the following PHP function will return true if a variable is an array or false if it is not an array?
A. this_array()
B. do_array()
C. is_array()
D. in_array()

Show Answer Answer:-C. is_array()
Explanation The function is_array() is an inbuilt function in PHP which is used to check whether a variable is an array or not. Its prototype follows: boolean is_array(mixed variable).

Q 5. 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()

Show Answer Answer:-D. array_push()
Explanation array_push adds a value to the end of an array, returning the total count of elements in the array after the new value has been added.

Q 6. 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) );

?>

A. 1
B. 2
C. False
D. True

Show Answer Answer:-B. 2
Explanation The array_search() function searches an array for a specified value, returning its key if located and FALSE otherwise.

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

<?php

$fruits = array (“apple”, “orange”, “banana”);

echo (next($fruits));

echo (next($fruits));

?>

A. orangeorange
B. appleorange
C. orangebanana
D. appleapple

Show Answer Answer:-C. orangebanana
Explanation The next() function returns the value of the next element in the array. In the first ‘next($fruits)’ call, it will print orange which is next to apple and so on.

Q 8. Which of the following function is used to get the value of the previous element in an array?
A. last()
B. before()
C. prev()
D. previous()

Show Answer Answer:-C. prev()
Explanation The prev() function returns the previous element in the array.

Q 9. 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

Show Answer Answer:-D. 6
Explanation The function count() will return the number of elements in an array. The parameter 1 counts the array recursively i.e it will count all the elements of multidimensional arrays.

Q 10. Which function returns an array consisting of associative key/value pairs?
A. array_count_values()
B. array_count()
C. count()
D. count_values()

Show Answer Answer:-A. array_count_values()
Explanation The function array_count_values() will count all the values of an array. It will return an associative array, where the keys will be the original array’s values, and the values are the number of occurrences.

Leave a Reply

Your email address will not be published. Required fields are marked *

Author

quizsquestion@gmail.com

Related Posts

Top 100 UK GK Questions (Culture, Sport & Icons)

🎭 Culture (1–35) Q 1. What is the capital of the United Kingdom? Show Answer Answer:-London Q 2. What is the official...

Read out all

Current Affairs Quiz – May 2026

Q 1.Which state has been declared the country’s first paperless judiciary state? A. SikkimB. ManipurC. AssamD. Odisha Show Answer Answer:- A. Sikkim...

Read out all

Culture Sport & Icons Australia GK Question Top 100

Australia’s identity is a vibrant blend of the world’s oldest living culture, a deep-seated passion for sport, and a unique collection of...

Read out all

Current Affairs Quiz – March 2026

Q 1.Where was India–UK Conference on Green Hydrogen Standards and Safety Protocols held? A. New DelhiB. ChennaiC. HyderabadD. Bengaluru Show Answer Answer:-A....

Read out all

Python Questions and Answers – Exception Handling – 3

Python Multiple Choice Questions & Answers (MCQs) focuses on “Exception Handling – 3”. Q 1. What happens if the file is not...

Read out all

Important Events & History Canadian Multiple Choice Question

Q 1. In what year did Canadian Confederation take place? A. 1776 B. 1812 C. 1867 D. 1982 Show Answer Answer:-C. 1867...

Read out all

You cannot copy content of this page