wolves Posted July 20, 2006 Share Posted July 20, 2006 first look at my arrays[code]//my first arrayArray( [key1] => Array ( [0] => Value1 [1] => Value2 [2] => Value3 [3] => Value4 [4] => Value5 [5] => Value6 [6] => Value7 [7] => Value8 [8] => Value9 ) [key2] => Array ( [0] => Value1 [1] => Value2 [2] => Value3 ) [key3] => Array ( [0] => Value2 [1] => Value2 ))//my second arrayArray( [key1] => Array ( [6] => Value7 [7] => Value8 [8] => Value9 ) [key2] => Array ( [0] => Value1 ) [key3] => Array ( [0] => Value2 ))[/code]Now there is a way to get an array that is the result of array1 less array2? and other that is what array2 have that array1 doesn't have, using native php functions?tks Quote Link to comment https://forums.phpfreaks.com/topic/15177-array-difference/ Share on other sites More sharing options...
zq29 Posted July 20, 2006 Share Posted July 20, 2006 array_diff()array_intersect()Check the manual for details. Quote Link to comment https://forums.phpfreaks.com/topic/15177-array-difference/#findComment-61208 Share on other sites More sharing options...
wolves Posted July 20, 2006 Author Share Posted July 20, 2006 I'm trying to use this functions but no functional results....array_diff($array1, $array2) returns empty arrayarray_diff($array2, $array1) returns empty arrayarray_intersect($array1, $array2) returns array2array_intersect($array2, $array1) return array1don't know how to get array1 - array2... Quote Link to comment https://forums.phpfreaks.com/topic/15177-array-difference/#findComment-61215 Share on other sites More sharing options...
ryanlwh Posted July 20, 2006 Share Posted July 20, 2006 you should loop through array1 and use array_diff on the second level arrays. the reason why you got empty array from array_diff is that this funciton is not recursive.[code]foreach($array1 as $key=>$arr){ $result[$key] = array_diff($arr,$array2[$key]);}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15177-array-difference/#findComment-61258 Share on other sites More sharing options...
wolves Posted July 20, 2006 Author Share Posted July 20, 2006 tks, it's solved my problemn Quote Link to comment https://forums.phpfreaks.com/topic/15177-array-difference/#findComment-61291 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.