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"];
  1.    population 11,35,000
  2.    karnataka population
  3.    karnataka 11,35,000
  4.    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?
  1.    array_unshift()
  2.    into_array()
  3.    inend_array()
  4.    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?
  1.    do_array()
  2.    is_array()
  3.    this_array()
  4.    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”);
  1.    2, 3 and 4
  2.    2 and 3
  3.    Only 1
  4.    3 and 4
Explanation:-
Answer: Option D. -> 3 and 4

Question 5. PHP’s numerically indexed array begin with position ______.
  1.    0
  2.    2
  3.    1
  4.    -1
Explanation:-
Answer: Option A. -> 0

Question 6. Which function can be used to move the pointer to the previous array position?
  1.    before()
  2.    last()
  3.    prev()
  4.    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));
  1.    orangeorange
  2.    appleapple
  3.    orangebanana
  4.    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.    1
  2.    2
  3.    True
  4.    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));
  1.    4
  2.    3
  3.    5
  4.    6
Explanation:-
Answer: Option D. -> 6

Question 10. Which function returns an array consisting of associative key/value pairs?
  1.    array_count_values()
  2.    count_values()
  3.    count()
  4.    array_count()
Explanation:-
Answer: Option A. -> array_count_values()