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”);
$result = array_intersect($a1, $a2);
print_r($result);
?>
a) Array ( [a] => red [b] => green [c] => blue )
b) Array ( [a] => red [b] => green [c] => blue [d] => yellow )
c) Array ( [e] => red [f] => green [g] => blue )
d) Array ( [a] => red [b] => green [c] => blue [d] => yellow [e] => red [f] => green [g] => blue )
Answer: a
Explanation: The function array_intersect() compares the values of two (or more) arrays, and returns the matches. So, in the above program values of a1 and a2 will be compared and the values present in both the arrays will be the returned.
Related Posts
Which of the following method scopes is/are not supported by PHP?
i) private
ii) friendly
iii) static
iv) abstractWhich of the following is/are the right way to declare a method?
i) function functionName() { function body }
ii) scope function functionName() { function body }
iii) method methodName() { method body }
iv) scope method methodName() { method body }Which one of the following is the right way to invoke a method?
Which one of the following is the right way to call a class constant, given that the class is mathFunction?
Which one of the following is the right way to define a constant?
Which one of the following can be used to instantiate an object in PHP assuming class name to be Foo?
Which one of the following property scopes is not supported by PHP?
Join The Discussion