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...?


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to