Please refer to the following link for more information ~~~~~~~~~~~~~~~~~~~~~~ The actual situation is that A and B have about 10 thousand data records. The result is c.txt. for details, see Section 333 ~~~~~~~~~~~~~~~~~~~~~~
The a.txt file is as follows:
123
222
333
444
555
666
777
888
999
000
The B .txt file is as follows:
123
222
444
666
000
If you do not use A data warehouse, removes B .txt data from a.txt. the actual situation is that A and B have approximately 10 thousand data records.
The result is c.txt. the content is as follows:
333
555
777
888
999
My idea is to read A and B to an array respectively, and then traverse A. if A row of data in A is not in B, the data is written to C.
I don't know if this idea is correct, but it is highly efficient.
------ Solution --------------------
Like you think, read the array and merge it.
Considering the large amount of data, you can read data separately. for example, two files read 100 lines each time. Then php has a special merging function, array_merge, which is very convenient.
------ Solution --------------------
No need to traverse.
Array_diff (array $ array1, array $ array2 [, array $...])
The returned array contains all values in the array of array1 but not in any other parameter array.
------ Solution --------------------
PHP code
Function w ($ cont, $ filename) {if (is_writable ($ filename) {if (! $ Handle = fopen ($ filename, 'A') {echo "cannot open the file $ filename"; exit;} if (fwrite ($ handle, $ cont) === FALSE) {echo "cannot be written to the file $ filename"; exit;} echo "successfully writes $ somecontent to the file $ filename"; fclose ($ handle );} else {echo "file $ filename cannot be written" ;}}$ cont_a = file_get_contents ("/path/filenameA"); $ arrA = explode ("\ n", $ cont_a ); $ cont_ B = file_get_contents ("/path/filenameB"); $ arrB = explode ("\ n", $ cont_ B); $ arrNewB = array_diff ($ arrB, $ arrA ); $ cont_newb = implode ("\ n", $ arrNewB); $ arrC = array_diff ($ arrA, $ arrB); $ cont_c = implode ("\ n", $ arrC ); w ($ cont_newb); w ($ cont_c );
------ Solution --------------------
It looks like the array_diff function + file function is enough. how is the efficiency of LZ.