...

View Full Version : Array comparison



apoth
04-17-2004, 02:46 PM
I have an array (call it $temp) and an array of arrays (call it $results).

I'd like to loop through the $results and see if the first element in $temp matches the first element of each array in $results.

Can anyone help me with how to do this?

Many thanks
Rich

raf
04-17-2004, 02:53 PM
Welcome here !

Something like


foreach($results as $var){
if ($var[0]!=$temp[0]){
echo ('Problem: mismatch found for ');
print_r($var);
}
}

apoth
04-17-2004, 02:54 PM
Thanks for the welcome :)

I haven't tried that yet, but it looks self explanatory and spot on for what I want, cheers :thumbsup:

raf
04-17-2004, 03:02 PM
You're welcome.

I just ran this


$status='ok';
$temp= array('1','2','3');
$results= array(array('1','3'),
array('1','4'),
array('2','10'));
foreach($results as $var){
if ($var[0]!=$temp[0]){
$status='not ok';
echo ('<br />Problem: mismatch found for ');
print_r($var);
}
}
echo ('<br />' . $status);

and it worked.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum