You really should also do a bit of work to make it easy for people to help you. I just spent 5 minutes decyphering your text file so I could reproduce your problem using this script:
<? $array1 = array( array("aus_name"=>"Videografik", "aus_id"=>"1"), array("aus_name"=>"Webdesign", "aus_id"=>"2"), array("aus_name"=>"gfg fd", "aus_id"=>"3"), array("aus_name"=>"df fds dfsdf", "aus_id"=>"4"), array("aus_name"=>"fdf'' dfd fds","aus_id"=>"5")); $array2 = array( array("aus_name"=>"Webdesign", "aus_id"=>"2"), array("aus_name"=>"Videografik", "aus_id"=>"1")); $n=0; foreach ($array2 as $diff) { $diff[$n]=array_diff($array1[$n], $array2[$n]); $all[] = array ("aus_name" => $diff[$n][aus_name], "aus_id" => $diff[$n][aus_id]); $n++; } var_dump ($all); ?> This is 5 minutes I normally wouldn't have spent and would just have skipped over your question because there was too much work for me. So, looking at this code, let's manually look at what happens in that foreach() loop of yours. You end up comparing the first element in array1 with the first element of array2 and on the second iteration you compare the second element of array1 with the second element of array2. Like this: array("aus_name"=>"Videografik", "aus_id"=>"1") vs. array("aus_name"=>"Webdesign", "aus_id"=>"2") and array("aus_name"=>"Webdesign", "aus_id"=>"2") vs. array("aus_name"=>"Videografik", "aus_id"=>"1") Now, the documentation for array_diff() states: array_diff() returns an array containing all the values of array1 that are not present in any of the other arguments. Note that keys are preserved. So, by looking at what you are comparing, and keeping what the array_diff() function is documented to do in mind, we would expect an output of: array("aus_name"=>"Videografik", "aus_id"=>"1") the first time through the loop as neither "Videografik" nor "1" appears in the second array which consists of array("aus_name"=>"Webdesign", "aus_id"=>"2") and the same goes for the second iteration. So, the output you are getting is exactly what you coded. Your main mistake: You forgot that PHP arrays are ordered. That is, the order by which elements are inserted is the order in which they appear when you loop through them with foreach. This resulted in you not comparing equivalent aus_id elements with each other. You also don't seem to handle the difference in the number of elements anywhere. If both sets starts with aus_id at 1 and go up from there, it is clear that if array1 has 5 elements and array2 only has 2, then aus_id 3, 4 and 5 from array1 are the different without even checking. You probably did realize this, and that is why you are doing the foreach() over array2, but nowhere do you put these last 3 elements into your difference array. I think the easiest way to handle this is to rethink your problem. Assuming you won't always have incrementing aus_id's the way you do and you don't know whether array1 or array2 will have more elements, I would suggest making a temp array keyed on the aus_id sorted correctly. Not very hard to do, just do this: foreach($array1 as $elem) $ar1[$elem['aus_id']] = $elem['aus_name']; foreach($array2 as $elem) $ar2[$elem['aus_id']] = $elem['aus_name']; ksort($ar1); ksort($ar2); Now, the real benefit of this approach is that you just need to call array_diff() once to get the diff you want. So here is the rewritten test script: $array1 = array( array("aus_name"=>"Videografik", "aus_id"=>"1"), array("aus_name"=>"Webdesign", "aus_id"=>"2"), array("aus_name"=>"gfg fd", "aus_id"=>"3"), array("aus_name"=>"df fds dfsdf", "aus_id"=>"4"), array("aus_name"=>"fdf'' dfd fds","aus_id"=>"5")); $array2 = array( array("aus_name"=>"Webdesign", "aus_id"=>"2"), array("aus_name"=>"Videografik", "aus_id"=>"1")); foreach($array1 as $elem) $ar1[$elem['aus_id']] = $elem['aus_name']; foreach($array2 as $elem) $ar2[$elem['aus_id']] = $elem['aus_name']; ksort($ar1); ksort($ar2); $diff = array_diff($ar1,$ar2); var_dump($diff); It's shorter, faster and it works. -Rasmus On Mon, 12 Aug 2002, Gandalf wrote: > Win2k Pro and the latest PHP Version > > At 21:17 11.08.2002 -0700, you wrote: > >First of all, which OS and PHP version? > > > >On Mon, 12 Aug 2002, Gandalf wrote: > > > > > > > > > > > Hello! > > > > > > First of all, i am trying to solve this problem for more then a week now, i > > > looked through php.net for hours and have posted on numerous boards but > > > nobody could come up and tell me what is going wrong. > > > > > > Basically, i have two multidimensional arrays, and i want to compare those > > > two using array_diff(). > > > > > > The problem is, that the output given is ecxactly the opposite of what > > i want. > > > > > > To make it easier for those willing to help, i placed the sample code in a > > > textfile so you can view it there. > > > > > > http://www.thebounceroom.com/problem.txt > > > > > > PLEASE, if you have some spare time have a look and tell me why this is not > > > working as it should, as by now i am really frustrated, ive lost a > > whole week > > > by now and everybody else has to wait just because of me. > > > > > > Thanks a lot in advance for your time reading this! > > > > > > With best regards from Vienna, > > > Jürgen > > > > > > > > > > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > >-- > >PHP General Mailing List (http://www.php.net/) > >To unsubscribe, visit: http://www.php.net/unsub.php > > Jürgen (aka. Frodo the scribe > ====================== > Visit the MECCG Forums at > http://www.coen.at.tf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php