PHP MCQ Quiz Hub

PHP Mcq Arrays

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

PHP’s numerically indexed array begin with position ___________





✅ Correct Answer: 3

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





✅ Correct Answer: 1

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





✅ Correct Answer: 2

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





✅ Correct Answer: 4

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





✅ Correct Answer: 4

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





✅ Correct Answer: 1

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





✅ Correct Answer: 3

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





✅ Correct Answer: 4

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





✅ Correct Answer: 3

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] . "."; ?>





✅ Correct Answer: 4

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





✅ Correct Answer: 4

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





✅ Correct Answer: 4

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





✅ Correct Answer: 1

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





✅ Correct Answer: 4

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





✅ Correct Answer: 1

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





✅ Correct Answer: 3

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] . "."; ?>





✅ Correct Answer: 2

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; ?>





✅ Correct Answer: 4

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





✅ Correct Answer: 1

A ________ is an array with more than two dimensions.





✅ Correct Answer: 2

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





✅ Correct Answer: 4

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





✅ Correct Answer: 4

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





✅ Correct Answer: 3

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





✅ Correct Answer: 4

As compared to associative arrays vector arrays are much





✅ Correct Answer: 1

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





✅ Correct Answer: 2

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"]; ?>





✅ Correct Answer: 2

Key/value pair can be initialized using = operator?





✅ Correct Answer: 1

What is the use of is_array() function?





✅ Correct Answer: 3

What is the use of array_unshift() function?





✅ Correct Answer: 2

What is the use of array_flip() function?





✅ Correct Answer: 2

What is the use of array_values() function?





✅ Correct Answer: 4

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





✅ Correct Answer: 4

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





✅ Correct Answer: 3

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





✅ Correct Answer: 3

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





✅ Correct Answer: 2

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] . "."; ?>





✅ Correct Answer: 2

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





✅ Correct Answer: 3

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





✅ Correct Answer: 4

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





✅ Correct Answer: 2

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





✅ Correct Answer: 1

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





✅ Correct Answer: 4

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





✅ Correct Answer: 3

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





✅ Correct Answer: 4

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





✅ Correct Answer: 1

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





✅ Correct Answer: 2

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





✅ Correct Answer: 3

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





✅ Correct Answer: 3

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





✅ Correct Answer: 3

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





✅ Correct Answer: 1

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





✅ Correct Answer: 4

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





✅ Correct Answer: 3

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





✅ Correct Answer: 4

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





✅ Correct Answer: 2