doublet216 Posted March 4, 2013 Share Posted March 4, 2013 I have a 2 dimensional array and I can't seem to get the difference between 2 arrays. Array([LineItem] => Array([1] => 1)[Product] => Array([1] => 1)) Array([Product] => Array([1] => 1)) $diff = array(); foreach($group as $key => $value) { foreach($group2 as $key2 $value2) { if($value[$key1] == $value2[$key2]) continue 2; } $diff[] = $value; } what i need is $diff to be Array( [LineItem] => Array([1] => 1)) Quote Link to comment https://forums.phpfreaks.com/topic/275199-multidimensional-array-diff/ Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 (edited) $diff = array_diff_key($array1, $array2); This will give you an array with all the keys in $array1 that were not present in $array2. Ex: $array1 = array('apple' => 'red', 'orange' => 'orange', 'lime' => 'green'); $array2 = array('apple' => 'green', 'lime' => 'yellow-ish green'); $diff = array_diff_key($array1, $array2); print_r($diff); This should print something like: array ( 'orange' => 'orange' ) Edited March 4, 2013 by haku Quote Link to comment https://forums.phpfreaks.com/topic/275199-multidimensional-array-diff/#findComment-1416365 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.