Arrays(Computer Science > Php Program ) Questions and Answers

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

Question 2. 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.    3 and 4
  2.    2 and 3
  3.    Only 1
  4.    2, 3 and 4
Explanation:-
Answer: Option A. -> 3 and 4

Question 3. Which function will return true if a variable is an array or false if it is not?
  1.    this_array()
  2.    is_array()
  3.    do_array()
  4.    in_array()
Explanation:-
Answer: Option B. -> is_array()

Question 4. What will be the output of the following php code?
  1.    karnataka 11,35,000
  2.    11,35,000
  3.    population 11,35,000
  4.    karnataka population
Explanation:-
Answer: Option B. -> 11,35,000

Question 5. 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 6. What will be the output of the following PHP code?
  1.    True
  2.    1
  3.    False
  4.    2
Explanation:-
Answer: Option D. -> 2

Question 7. What will be the output of the following PHP code?
  1.    orangebanana
  2.    appleorange
  3.    orangeorange
  4.    appleapple
Explanation:-
Answer: Option A. -> orangebanana

Question 8. Which function can be used to move the pointer to the previous array position?
  1.    last()
  2.    before()
  3.    prev()
  4.    previous()
Explanation:-
Answer: Option C. -> prev()

Question 9. What will be the output of the following PHP code?
  1.    3
  2.    4
  3.    5
  4.    6
Explanation:-
Answer: Option D. -> 6

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