If you want to compute the difference of two or more than 2 array with index means to compare 2 array with the index of arrays for this you can use the predefined PHP function "array_diff_assoc()".
array_diff_assoc() compares array1 against array2 and returns the difference as array.The difference with array_diff() is, the array keys used in the comparison.
Here is a example which explain this-
<?php
$array1 = array("a" => "one", "b" => "two", "c" => "three", "four");
$array2 = array("a" => "one", "two", "four");
$result = array_diff_assoc($array1, $array2);
print_r($result);
?>
Output:
Array
(
[b] => two
[c] => three
[0] => four
)
In this example "one" exist in both array with same index and "four" exist in both but key is different.
0 Comment(s)