Correct:
array(0) { }
Explanation:
The array_intersect_assoc()
function checks whether the index keys as well as their respective key values between/among the given arrays are the same or not. For example, a PHP script is given as follows:
<?php
$array1 = array ('a' => 20, 30, 35);
$array2 = array ('b' => 20, 35, 30);
$array = array_intersect_assoc ($array1, $array2);
var_dump ($array);
?>
However, all values in $array1
and `$array2 are the same and their respective index keys are not the same. Hence, the output of the above script will be
array(0) { }
which means that there will be no element in $array since the index keys of $array1
are not equal to the index keys of $array2
.
Here is another example:
<?php
$array1 = array ('a' => 20, 30, 35);
$array2 = array ('a' => 20, 35, 30);
$array = array_intersect_assoc ($array1, $array2);
var_dump ($array);
?>
The output of the above script will be
{ ["a"]=> int(20) }
since there is one index key and its respective value ('a' => 20) is the same in both arrays, i.e., $array1
and $array2
.
Answer option B is incorrect. You can retrieve this output when you are using the array_intersect()
function instead of the array_intersect_assoc()
function. The array_intersect()
function extracts all the elements that are common for two or more arrays. Since this function only checks whether the values are the same, the index keys of arrays are ignored. For example, a user runs the following script:
<?php
$array1 = array ('a' => 20, 30, 35);
$array2 = array ('b' => 20, 35, 30);
$array = array_intersect($array1, $array2);
var_dump ($array);
?>
The output of the above script will be
array(3) { ["a"]=> int(20) [0]=> int(30) [1]=> int(35) }
since three elements (20, 30, 35) are common in both arrays, i.e., $array1
and $array2
.
Answer options A and D are incorrect. These are invalid outputs.
Reference: http://in2.php.net/manual/en/function.array-intersect-assoc.php