Schlo_50 Posted May 27, 2008 Share Posted May 27, 2008 Hi there, I have a script which defines two variables from two separate lists. I need to now use some php to go through the variables and print out any matches. My code, is below. I am looking to match $lookup and $find. $lines = file("data/sub_categories.DAT"); foreach ($lines as $line) { $data[$key] = explode("|", $line); $lookup = $data[$key][2]; } $linesb = file("data/threads.DAT"); foreach ($linesb as $lineb) { $datab[$keyb] = explode("|", $lineb); $find = $datab[$keyb][2]; } if ($lookup == $find) { print "Match"; } Thanks in advance. (Sorry about my other post, I made some mistakes in code, and explained my problem wrongly) Link to comment https://forums.phpfreaks.com/topic/107413-solved-matching-variables/ Share on other sites More sharing options...
Schlo_50 Posted May 27, 2008 Author Share Posted May 27, 2008 Obviously this isn't generating any errors, and won't find a match because my if statement is outside of the loops therefore the variables are only being assigned the last value of each list. How would I fix this? I tried putting the second foreach() inside the first but that crashed the browser..lol Link to comment https://forums.phpfreaks.com/topic/107413-solved-matching-variables/#findComment-550631 Share on other sites More sharing options...
Barand Posted May 27, 2008 Share Posted May 27, 2008 try <?php $lines = file("data/sub_categories.DAT"); foreach ($lines as $line) { $data = explode("|", $line); $lookup[] = trim($data[2]); } $linesb = file("data/threads.DAT"); foreach ($linesb as $lineb) { $datab = explode("|", $lineb); $find = trim($datab[2]); if (in_array($find, $lookup)) { echo "Match : $find<br>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/107413-solved-matching-variables/#findComment-550637 Share on other sites More sharing options...
Schlo_50 Posted May 27, 2008 Author Share Posted May 27, 2008 Thanks! Link to comment https://forums.phpfreaks.com/topic/107413-solved-matching-variables/#findComment-550652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.