Jump to content

Problem with my ARRAY_DIFFERENCE script.


cuboidgraphix

Recommended Posts

Hi again guys, Well i have this array_difference script code that works whenever I have numbers like.... 

 

1

2

3

4

5

6

7

8

9

10

11

etc...

 

In each text file, but it does not seem to work when I have numbers such as,

 

2800001

2801000

2801010

2801011

2801012

2810123

6600000

6701050

6701052

 

Can you see if anything is wrong with my code?

 

<?php
// Array Difference Script
$hlr = @fopen('hlr.txt', 'r');
if ($hlr){
$array1 = explode("\n", fread($hlr, filesize("hlr.txt")));
} 

$vlr = @fopen('vlr.txt', 'r');
if ($vlr){
$array2 = explode("\n", fread($vlr, filesize("vlr.txt")));
}

$diff = array_diff($array1, $array2);
foreach ($diff as $value){
  echo $value . " 
";
} 	
?> 

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/102951-problem-with-my-array_difference-script/
Share on other sites

what do you mean the format of the numbers?  I just copied and pasted them on a notepad and saved them as text.  I don't get any error messages. Just a blank page.

 

I have two files... hlr.txt  and vlr.txt    when I clean the file and type in...

 

1

2

3

4

5

6

7

8

9

10

etc.. 

and in the other file

4

5

6

 

It works... I get ...

1

2

3

7

8

9

etc.

 

I doesn't work when I paste the 7 digit numbers..

 

Do you have your error_reporting set to E_ALL?

 

Try var_dump() on your $diff variable. array_diff() isn't supposed to fail, so I'm really sure it's your input variables that are faulty. try checking them with print_r() too.

 

Which version of PHP are you using?

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.