"Kevin Stone" <[EMAIL PROTECTED]> wrote: > I think you're trying to defy logic here. How will the function know that > you want to keep color=>cherry or flavor=>cherry? What logical construct > makes that decision? The example you've given will result in an array that > looks eactly like $arr1 regardless of the content in either array.
i beg to diff-er (haha, i'm so punny:). the function i wrote works the way i want it to, but perhaps i neglected to mention that it only works on purely associative arrays, i.e. string keys only. try this one: $arr1 = array("name" => "Bing", "color" => "red", "flavor" => "cherry"); $arr2 = array("name" => "Bing", "color" => "cherry", "flavor" => "red"); print_r(myArrayDiff($arr2, $arr1)); output: Array ( [color] => cherry [flavor] => red ) in words, the difference between arr2 and arr1 is that "color" changed to "cherry", and "flavor" changed to "red". /nick > > function myArrayDiff($thing1, $thing2) > > { > > $diff = array(); > > while (list($key, $val) = each($thing1)) > > { > > if ((string)$val !== (string)$thing2[$key]) > > $diff[$key] = $val; > > } > > > > return $diff; > > } > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php