问题描述:

I have a problem and I hope, I can be helped to fix this problem.

My problem is I got this two arrays

$array1 = ["test1" => "red", "test2" => "blue", "test3" => "green"];

$array2 = ["test1" => "red", "test2" => "blue", "test3" => "blue"];

as you can see the difference is the array key test3's value there are a diff, my problem is i need to know the key test3 have a diff and from $array1 to $array2

I have tried array_diff and array_intersect but its not what I want.

I have a product and i need to know what there are changes from last run, and if i use on of this to command its not telling my where the diff are but what the diff is.

Can somebody help here and explain what i can do or about there are a function to handle this problem?

网友答案:
<?php
$array1 = ["test1" => "red", "test2" => "blue", "test3" => "green"];
$array2 = ["test1" => "red", "test2" => "blue", "test3" => "blue"];

$result=array_diff($array1,$array2);
print_r($result);
?>

This shud work
o/p : Array ( [test3] => green ) 
网友答案:
<?php
    $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "d" => "red");
    $array2 = array("a" => "green", "b" => "brown", "c" => "blue", "d" => "yellow");
    $result = array_diff_assoc($array1, $array2);
    echo print_r($result, true);
?>
相关阅读:
Top