Examveda
Examveda

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

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.

This Question Belongs to PHP >> Arrays

Join The Discussion

Comments ( 3 )

  1. عبووود الأسطا
    عبووود الأسطا :
    2 years ago

    maybe this code will result as :
    Array ( [i] => orange )
    because the array_diff is not between $a4 and $a1

  2. SK S
    SK S :
    5 years ago

    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.

  3. SK S
    SK S :
    5 years ago

    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.

Related Questions on Arrays