When defining the following, please
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");$a2=array("e"=>"red","f"=>"green","g"=>"blue");$result=array_diff($a1,$a2);print_r($result);
Returns the difference set to Array ([d] = = yellow)
But if we put them upside down, why can't we find the $a2 in front of them?
$result=array_diff($a2,$a1);
Reply content:
When defining the following, please
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");$a2=array("e"=>"red","f"=>"green","g"=>"blue");$result=array_diff($a1,$a2);print_r($result);
Returns the difference set to Array ([d] = = yellow)
But if we put them upside down, why can't we find the $a2 in front of them?
$result=array_diff($a2,$a1);
The difference sets are sequential, as if they were 4 - 3
not equal 3 - 4
. This example is not very reasonable, so you will feel that you can not find the difference set, in fact, $a2
and $a1
the difference is empty, so it looks like there is no difference set. You can make it $b = array("e"=>"red","f"=>"green","g"=>"blue","h"=>"gray");
so that you can immediately understand what the difference is.
Array Array_diff (array $array 1, array $array 2)
The comparison returns the values in Array1 but not in the array2 and any other parameter arrays.
After the reversal, of course there is no
Read the manual carefully
Http://www.w3school.com.cn/php/func_array_diff.asp
Thank you for inviting me. A few references upstairs are enough for you to use. Array_diff