What will be the output of the following PHP code? [code] <?php $a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow"); $a2 =

What will be the output of the following PHP code?
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);
?>
A. Array ( [d] => yellow )
B. Array ( => orange )
C. Array ( [h] => orange )
D. Array ( [d] => yellow [h] => orange )
 
Answer: a
Explanation: The array_diff() function compares the values of two (or more) arrays, and returns the differences. This function compares the values of two (or more) arrays, and return an array that contains the entries from array1 that are not present in other arrays (array2, array3, etc).
 

Tìm kiếm

Back
Top