Filter rows of a 2d array by the rows in another 2d array

Two values from key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In other words a strict check takes place so the string representations must be the same. http://php.net/manual/en/function.array-diff-assoc.php The (string) value of any array is “Array”. Thus, your call to array_diff_assoc is effectively comparing these two things: Array … Read more

What is the difference between array_udiff_assoc() and array_diff_uassoc()?

They both do the same, but udiff-assoc compares the DATA with the user supplied function, while diff-uassoc compares the INDEX with the user supplied function. As an answer to @lonsesomeday : as indicated by the ‘u’, diff_assoc will use internal functions for all comparisons, and udiff_uassoc uses provided callbacks for index and data comparison. http://www.php.net/manual/en/function.array-diff-uassoc.php … Read more

Compare two 2D arrays & get intersection and differences

Convert arrays to a format, where array index is the sight_id: $b1 =array(); foreach($a1 as $x) $b1[$x[‘sight_id’]] = $x[‘location’]; $b2 =array(); foreach($a2 as $x) $b2[$x[‘sight_id’]] = $x[‘location’]; Calculate the differences and intersection: $c_intersect = array_intersect_key($b1,$b2); $c_1 = array_diff_key($b1,$b2); $c_2 = array_diff_key($b2,$b1); Convert arrays back to your format: $intersect_array = array(); foreach($c_intersect as $i=>$v) $intersect_array[] = … Read more

Get difference between associative rows of two 2-dimensional arrays

To check multi-deminsions try something like this: $pageWithNoChildren = array_map(‘unserialize’, array_diff(array_map(‘serialize’, $pageids), array_map(‘serialize’, $parentpage))); array_map() runs each sub-array of the main arrays through serialize() which converts each sub-array into a string representation of that sub-array the main arrays now have values that are not arrays but string representations of the sub-arrays array_diff() now has a … Read more

Compare 2-dimensional data sets based on a specified second level value

You can define a custom comparison function using array_udiff(). function udiffCompare($a, $b) { return $a[‘ITEM’] – $b[‘ITEM’]; } $arrdiff = array_udiff($arr2, $arr1, ‘udiffCompare’); print_r($arrdiff); Output: Array ( [3] => Array ( [ITEM] => 4 ) ) This uses and preserves the arrays’ existing structure, which I assume you want.