Fw: [PHP] Re: wanted: array_diff for more than values

From: Date: Fri, 08 Nov 2002 23:39:05 +0000
Subject: Fw: [PHP] Re: wanted: array_diff for more than values
Groups: php.general 
Request: Send a blank email to php-general+get-123508@lists.php.net to get a copy of this message
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. $arr1 = array("color" => "red", "flavor" => "cherry"); $arr2 = array("color" => "cherry", "flavor" => "red"); print_r(myArrayDiff($arr1, $arr2)); -Kevin ----- Original Message ----- From: "Nick Eby" <nick_eby@bonzidev.com> To: <php-general@lists.php.net> Sent: Friday, November 08, 2002 4:15 PM Subject: [PHP] Re: wanted: array_diff for more than values > in case anyone cares, here is my solution so far, please comment if you feel > the need. > > 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 > >

« previous php.general (#123508) next »