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_combine($a2, $a3);
$result = array_diff($a4, $a2);
print_r($result);
?>
<?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_combine($a2, $a3);
$result = array_diff($a4, $a2);
print_r($result);
?>
A. Array ( [d] => yellow )
B. Array ( [i] => orange )
C. Array ( [h] => orange )
D. Array ( [d] => yellow [h] => orange )
Answer: Option A
Solution(By Examveda Team)
The array_diff() function compares the values of two (or more) arrays, and returns the differences.Join The Discussion
Comments ( 3 )
Related Questions on Arrays
A. karnataka 11,35,000
B. 11,35,000
C. population 11,35,000
D. karnataka population
Which function will return true if a variable is an array or false if it is not?
A. this_array()
B. is_array()
C. do_array()
D. in_array()
maybe this code will result as :
Array ( [i] => orange )
because the array_diff is not between $a4 and $a1
It should be $a = array_merge($a2, $a3);
array_combine() give warning if both array's parameter have not same.
many of question's answer are wrong. Please check it.
It should be $a = array_merge($a2, $a3);
array_combine() give warning if both array's parameter have not same.
many of question's answer are wrong. Please check it.