2

I'm comparing two arrays which each have 5000 values. (An example value is: 123456789)

I want to know if there is a faster way to compare two arrays than array_diff()

Mike
  • 23,542
  • 14
  • 76
  • 87
Adem
  • 55
  • 3
  • 6
  • 1
    Voting to close as dup but also upvoting since this question is much clearer and more accessible. – djechlin Feb 22 '13 at 22:37
  • 1
    You need to ask yourself why you have an array with 5K elements in it. If from a DB query you can run a limit via pagination, otherwise, there is no real reason to have an array this large. – Mike Purcell Feb 22 '13 at 22:40
  • @MikePurcell Since OP is dealing with numbers, it could be likely that the data is being fetched to create a CSV or Excel file for which 5k entries would be acceptable, just a guess though. – kittycat Feb 22 '13 at 22:42
  • @crypticツ: then he should be approaching the using an unbuffered approach where we read the file line by line vs loading the entire file into memory. – Mike Purcell Feb 22 '13 at 22:43
  • @MikePurcell that would be if OP is reading a file, I was saying OP is *creating* a file by using data from database. – kittycat Feb 22 '13 at 22:48
  • @crypticツ: Writing elements to a file via a query can be done in a paginated manner where this 'array' doesn't contain 5000 elements. Although it does result in more queries to the database. – Mike Purcell Feb 22 '13 at 22:51

0 Answers0