Sail E0 Webinar

MCQs

Total Questions : 16 | Page 1 of 2 pages
Question 1. PHP's numerically indexed array begin with position __.
  1.    1
  2.    2
  3.    0
  4.    -1
 Discuss Question
Answer: Option C. -> 0


Like many programming languages, the first element of an array has an index value of 0.


Question 2. Which of the functions is used to sort an array in descending order?
  1.    sort()
  2.    asort()
  3.    rsort()
  4.    dsort()
 Discuss Question
Answer: Option C. -> rsort()


sort() function is used to sort in ascending order where as rsort() meaning reverse sort is used for sorting in descending order.


Question 3. 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"];
?>
  1.    karnataka 11,35,000
  2.    11,35,000
  3.    population 11,35,000
  4.    karnataka population
 Discuss Question
Answer: Option B. -> 11,35,000


Treat states as a multidimensional array and accordingly traverse it to get the value.


Question 4. What will be the output of the following PHP code?
< ?php
$fruits = array ("mango", "apple", "pear", "peach");
$fruits = array_flip($fruits);
echo ($fruits[0]);
?>
  1.    mango
  2.    Error
  3.    peach
  4.    0
 Discuss Question
Answer: Option B. -> Error


As we are flipping the values, $fruits["mango"] = 0, $fruits["apple"] = 1 and so on.


Question 5. 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);
  1.    (iii) and (iv)
  2.    (ii) and (iii)
  3.    Only (i)
  4.    (ii), (iii) and (iv)
 Discuss Question
Answer: Option A. -> (iii) and (iv)


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.


Question 6. 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()
 Discuss Question
Answer: Option B. -> is_array()


A built-in function, is_array(), is available for testing an array. Its prototype follows: boolean is_array(mixed variable).


Question 7. What will be the output of the following PHP code?
< ?php
$fruits = array ("apple", "orange", "banana");
echo (next($fruits));
echo (next($fruits));
?>
  1.    orangebanana
  2.    appleorange
  3.    orangeorange
  4.    appleapple
 Discuss Question
Answer: Option A. -> orangebanana


The next() function returns the array value residing at the position immediately following that of the current array pointer.


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


prev()


Question 9. 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) );
?>
  1.    True
  2.    1
  3.    False
  4.    2
 Discuss Question
Answer: Option D. -> 2


The array_search() function searches an array for a specified value, returning its key if located and FALSE otherwise.


Question 10. 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()
 Discuss Question
Answer: Option D. -> array_push()


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.


Latest Videos

Latest Test Papers