Jump to content

[SOLVED] Matching variables.


Schlo_50

Recommended Posts

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

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

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>";
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.