Php Arrays(Engineering > Computer Science And Engineering > Php ) Questions and Answers
Question 1. What will be the output of the following php code?$states = array("karnataka" => array( "population" => "11,35,000", "captial" => "Bangalore"),"Tamil Nadu" => array( "population" => "17,90,000","captial" => "Chennai") );echo $states["karnataka"]["population"];
population 11,35,000
karnataka population
karnataka 11,35,000
11,35,000
Explanation:-
Answer: Option D. -> 11,35,000
Question 2. Which in-built function will add a value to the end of an array?
array_unshift()
into_array()
inend_array()
array_push()
Explanation:-
Answer: Option D. -> array_push()
Question 3. Which function will return true if a variable is an array or false if it is not?
do_array()
is_array()
this_array()
in_array()
Explanation:-
Answer: Option B. -> is_array()
Question 4. 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”);
2, 3 and 4
2 and 3
Only 1
3 and 4
Explanation:-
Answer: Option D. -> 3 and 4
Question 5. PHP’s numerically indexed array begin with position ______.
0
2
1
-1
Explanation:-
Answer: Option A. -> 0
Question 6. Which function can be used to move the pointer to the previous array position?
before()
last()
prev()
previous()
Explanation:-
Answer: Option C. -> prev()
Question 7. What will be the output of the following PHP code?$fruits = array ("apple", "orange", "banana");echo (next($fruits));echo (next($fruits));
orangeorange
appleapple
orangebanana
appleorange
Explanation:-
Answer: Option C. -> orangebanana
Question 8. What will be the output of the following PHP code?$state = array ("Karnataka", "Goa", "Tamil Nadu", "Andhra Pradesh");echo (array_search ("Tamil Nadu", $state) );
1
2
True
False
Explanation:-
Answer: Option B. -> 2
Question 9. What will be the output of the following PHP code?$fruits = array ("apple", "orange", array ("pear", "mango"), "banana");echo (count($fruits, 1));
4
3
5
6
Explanation:-
Answer: Option D. -> 6
Question 10. Which function returns an array consisting of associative key/value pairs?