function ArrayCompare($array1, $array2)
{       $answer = new Array()
        foreach ($array1 as $element)
        {       if (($key = array_search($element, $array2)) === false)
                {       $answer[$key] = $array2[$key];
                }
        }
        return $answer;
}

this will return an array that is a copy of the first array with only those
elements that are not in array2. If you only want the first one either just
use the first one( foreach(){ ... break;}) or put a break in the if.

        Tim Ward
        Senior Systems Engineer

Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html


> -----Original Message-----
> From: Jimmy Bäckström [mailto:[EMAIL PROTECTED]]
> Sent: 05 March 2001 06:38
> To: PHP General List
> Subject: Function to compare an array with another array
> 
> 
> Shu!
> I need some help here.
> I have a script where I want to compare two arrays with 
> eachother, and return one value from that does not exists in 
> both arrays. I have an array of pictures id number created 
> from a database query. I use sessions to save id numbers of 
> pictures into an array. I want the first array to be compared 
> to the second and return the first key/value-pair that are 
> not found in the session array...
> Is there a way I can do this? 
> 
> Thankful for any help!
> /Broder B
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to