I have two files.
First one has 482 lines. Second one has only 519 lines.
I would like to find extra lines by comparing two files using php.
Lets say my first file has lines like this
Mango
Orange
Cherry
Apple
Blackberry
And lets say my second file looks like this
Apple
Orange
Mango
Banana
Cherry
Blackberry
Please note: The lines are in random order. Now i would like to use a php script to remove the same lines and keep the extra lines. For example File 1 contains line Mango
. File 2 also contains that line but in random order. So i want to remove that line.
I took the same approach JYelton has suggested.
Demo here: http://codepad.org/lCa68G76
<?
$file1 = array(
'Mango',
'Orange',
'Cherry',
'Apple',
'Blackberry'
);
$file2 = array(
'Apple',
'Orange',
'Mango',
'Banana',
'Cherry',
'Blackberry'
);
foreach($file2 as $line)
{
if (!in_array($line, $file1))
{
$output[] = $line;
}
}
var_dump($output);
?>