Since individual files are individually sorted, you can perform a merge sort type.
Here is some pseudo code:
A -> File 1
B -> File 2
C -> SortedFile
While(A and B have lines left){
Left = NextLineFromA
Right= NextLineFromB
If = Left < Right // strcmp(...)
Write Left to C
Else
Write Right to C
}
// Now either A or B will have lines left
Write all lines left from A||B to C
Or you can read them, do array_merge () and then sort ()
I think it will be faster because you do not need to re-sort everything when you call sort ()
The php collation function is a quick O (n log (n)) collation algorithm, and thus O (n)
source
share