My Report

PHP Array Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

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

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

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

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

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

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

7. What will be the output of the following PHP code?

<?php
$place = array("NYC", "LA", "Paris");
array_pop($place);
$place1 = array("Paris");
$place = array_merge($place, $place1);
print_r($place);
?>

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

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

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

 

Start practicing “1000 MCQs on PHP”, and once you are ready, you can take tests on all topics by attempting our “PHP Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.