Sail E0 Webinar

MCQs

Total Questions : 16 | Page 2 of 2 pages
Question 11. What will be the output of the following PHP code?
< ?php
$number = array ("4", "hello", 2);
echo (array_sum ($number));
?>
  1.    4hello2
  2.    4
  3.    2
  4.    6
 Discuss Question
Answer: Option D. -> 6


The array_sum() function add all the values of the input array together, returning the final sum. If a string datatype is found, it'll be ignored.


Question 12. What will be the output of the following PHP code?
< ?php
$fruits = array ("apple", "orange", array ("pear", "mango"),
"banana");
echo (count($fruits, 1));
?>
  1.    3
  2.    4
  3.    5
  4.    6
 Discuss Question
Answer: Option D. -> 6


The array entity holding pear and mango is counted as an item, just as its contents are.


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


The array_splice() function removes all elements of an array found within a specified range.


Question 14. What will be the output of the following PHP code?
< ?php
$fruits = array ("apple", "mango", "peach", "pear",
"orange");
$subset = array_slice ($fruits, 2);
print_r ($subset);
?>
  1.    Array ( [0] => peach )
  2.    Array ( [0] => apple [1] => mango [2] => peach )
  3.    Array ( [0] => apple [1] => mango )
  4.    Array ( [0] => peach [1] => pear [2] => orange )
 Discuss Question
Answer: Option D. -> Array ( [0] => peach [1] => pear [2] => orange )


The array_slice() function returns a section of an array based on a starting and ending offset value.


Question 15. Say in the above question you need to get the array sorted in the manner we humans would have done it i.e picture1 then picture2 etc.. Which of the following function should be used?
  1.    dsort()
  2.    casesort()
  3.    natcasesort()
  4.    naturalsort()
 Discuss Question
Answer: Option C. -> natcasesort()


natcasesort()


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


array_count_values()


Latest Videos

Latest Test Papers