Re: comparing two arrays

From: Date: Wed, 02 Jul 2003 19:07:37 +0000
Subject: Re: comparing two arrays
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-153761@lists.php.net to get a copy of this message
Michael A Smith wrote:
Look at array_diff() (http://php.net/array_diff). That ought to do what you want.
Yes! Thank you :)
-Michael On Wed, 2003-07-02 at 10:15, Shena Delian O'Brien wrote:
Hi - I have two arrays that need to be compared. I need to know if their values match or not. Currently I have: $array1 = array(a, b, c, d); $array2 = array(c, d, e, f, g); $intersect = array_intersect($array1,$array2); $num1 = count($array1); $num2 = count($intersect); Then I can compare $num1 to $num2 to see where I stand on the comparison. Less than, greater than, or equal. Only there's a problem with this if there are identical values in an array: $array1 = array(e, e); $array2 = array(c, d, e, f, g); The intersect for this returns e twice instead of the once that I need for my code. It's true that in array1 there was indeed two matches, but in array2 there was only 1 match, and that is the match that matters in my code. Does this make sense? Is there a way to do this that I'm missing...?
-- Give to a good cause! * http://www.modestneeds.org/ Shena Delian O'Brien * http://www.darklock.com/shena/ The Graphics Kitty! * http://www.darklock.com/abstract/ Fantasy Age * http://www.fantasyage.com/

« previous php.general (#153761) next »