PHP MCQ Quiz Hub

PHP Mcq Arrays

Choose a topic to test your knowledge and improve your PHP skills

1. PHP’s numerically indexed array begin with position ___________




2. 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");




3. Which of the following PHP function will return true if a variable is an array or false if it is not an array?




4. Which in-built function will add a value to the end of an array?




5. 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) ); ?>




6. What will be the output of the following PHP code? <?php $fruits = array ("apple", "orange", "banana"); echo (next($fruits)); echo (next($fruits)); ?>




7. Which of the following function is used to get the value of the previous element in an array?




8. What will be the output of the following PHP code? <?php $fruits = array ("apple", "orange", array ("pear", "mango"), "banana"); echo (count($fruits, 1)); ?>




9. Which function returns an array consisting of associative key/value pairs?




10. What will be the output of the following PHP code? <?php $cars = array("Volvo", "BMW", "Toyota"); echo "I like " . $cars[2] . ", " . $cars[1] . " and " . $cars[0] . "."; ?>




11. What will be the output of the following PHP code? <?php $fname = array("Peter", "Ben", "Joe"); $age = array("35", "37", "43"); $c = array_combine($age, $fname); print_r($c); ?>




12. What will be the output of the following PHP code? <?php $a=array("A","Cat","Dog","A","Dog"); $b=array("A","A","Cat","A","Tiger"); $c=array_combine($a,$b); print_r(array_count_values($c)); ?>




13. What will be the output of the following PHP code? <?php $a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow"); $a2 = array("e" => "red", "f" => "green", "g" => "blue", "h" => "orange"); $a3 = array("i" => "orange"); $a4 = array_merge($a2, $a3); $result = array_diff($a1, $a4); print_r($result); ?>




14. What will be the output of the following PHP code? <?php $a1 = array("red", "green"); $a2 = array("blue", "yellow"); $a3 = array_merge($a1, $a2); $a4 = array("a", "b", "c", "d"); $a = array_combine($a4, $a3); print_r($a); ?>




15. What will be the output of the following PHP code? <?php $a = array("a" => "india", "b" => "brazil", "c" => "china"); echo array_shift($a); echo "<br>"; array_pop($a); print_r($a); ?>




16. What will be the output of the following PHP code? <?php $a1 = array_fill(1, 4, "hello"); $b1 = array_fill(5, 1, "php"); $a2 = array_merge($a1, $a2); print_r($a2); echo "<br>"; print_r($b1); ?>




17. What will be the output of the following PHP code? <?php $names = array("Sam", "Bob", "Jack"); echo $names[0] . "is the brother of " . $names[1] . " and " . $names[1] . "."; ?>




18. What will be the output of the following PHP code? <?php $names = array("Sam", "Bob", "Jack"); echo $names[0]."is the brother of ".$names[1]." and ".$names[1].".".$brother; ?>




19. By default, the index of array in php starts from ______?




20. A ________ is an array with more than two dimensions.




21. Which of the following are correct ways of creating an array? i) arr[0] = "letsfindcourse"; ii) $arr[] = array("letsfindcourse"); iii) $arr[0] = "letsfindcourse"; iv) $arr = array("letsfindcourse");




22. Which in-built function will add a value to the end of an array?




23. Which function returns an array consisting of associative key/value pairs?




24. What will be the output of the following PHP code? <?php $arr = array ("lets", "find", "course", ".Com"); echo (array_search (".com", $arr) ); ?>




25. As compared to associative arrays vector arrays are much




26. What is the output of the following php code? <?php $alphabet = array ("A", "B", "C"); echo (next($alphabet)); ?>




27. What is the output of the following php code? <?php $alphabet = array("A" => array ( "php" => "php 7.0", "date" => "3 December 2019"), "B" => array( "python" => "python 3.8.2", "date" => "24 December 2019") ); echo $alphabet ["A"]["date"]; ?>




28. Key/value pair can be initialized using = operator?




29. What is the use of is_array() function?




30. What is the use of array_unshift() function?




31. What is the use of array_flip() function?




32. What is the use of array_values() function?




33. Predict the output of the following code. <?php $a=array(1,2,3,5,6); next($a); next($a); next($a); echo current($a); ?>




34. Predict the output of the following PHP code. <?php $fruits = array ("apple", "orange", "banana", "guava", "pine-apple", "papaya", "melon"); next($fruits); next($fruits); prev($fruits); ?>




35. Which of the following function is used to get the value of the previous element in an array?




36. Which of the following function is Used to set the array pointer to the value of last key?




37. What will be the output of the following PHP code? <?php $cars = array("Volvo", "BMW", "Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?>




38. What will be the output of the following PHP code? <?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); print_r(array_change_key_case($age, CASE_UPPER)); ?>




39. What will be the output of the following PHP code? <?php $cars = array("Volvo", "BMW", "Toyota", "Honda", "Mercedes", "Opel"); print_r(array_chunk($cars, 2)); ?>




40. What will be the output of the following PHP code? <?php $fname = array("Peter", "Ben", "Joe"); $age = array("35", "37", "43"); $c = array_combine($fname, $age); print_r($c); ?>




41. What will be the output of the following PHP code? <?php $a = array("A", "Cat", "Dog", "A", "Dog"); print_r(array_count_values($a)); ?>




42. What will be the output of the following PHP code? <?php $a1 = array_fill(3, 4, "blue"); $b1 = array_fill(0, 1, "red"); print_r($a1); echo "<br>"; print_r($b1); ?>




43. What will be the output of the following PHP code? <?php $a1 = array("red", "green"); $a2 = array("blue", "yellow"); print_r(array_merge($a1, $a2)); ?>




44. What will be the output of the following PHP code? <?php $a = array("a"=>"red", "b"=>"green", "c"=>"blue"); echo array_shift($a); print_r ($a); ?>




45. What will be the output of the following PHP code? <?php $a = array("red", "green", "blue"); array_pop($a); print_r($a); ?>




46. What will be the output of the following PHP code? <?php $fruits = array ("mango", "apple", "pear", "peach"); $fruits = array_flip($fruits); echo ($fruits[0]); ?>




47. Which of the functions is used to sort an array in descending order?




48. What will be the output of the following PHP code? <?php $arr = array ("picture1.JPG", "picture2.jpg", "Picture10.jpg", "picture20.jpg"); sort($arr); print_r($arr); ?>




49. Which function should we use to sort the array in natural order?




50. What will be the output of the following PHP code? <?php $face = array ("A", "J", "Q", "K"); $number = array ("2","3","4", "5", "6", "7", "8", "9", "10"); $cards = array_merge ($face, $number); print_r ($cards); ?>




51. 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); ?>




52. 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); ?>




53. What will be the output of the following PHP code? <?php $number = array ("4", "hello", 2); echo (array_sum ($number)); ?>




54. What will be the output of the following PHP code? <?php $array1 = array ("KA", "LA", "CA", "MA", "TA"); $array2 = array ("KA", "IA", "CA", "GA", "TA"); $inter = array_intersect ($array1, $array2); print_r ($inter); ?>