Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6125
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: in_array performance in unsorted vs sorted array |
| Date | 2012-05-23 08:16 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <jpikfl$kae$1@dont-email.me> (permalink) |
| References | <jphvj0$acu$1@dont-email.me> |
On 5/23/2012 2:20 AM, William Gill wrote: > I am reading transaction records from files. Each record has an > alphanumeric GUID but that record may be repeated in more than one file > (because of overlapping samples). I don't want to process duplicate > records, so I am considering a simple flat file to store the GUID's of > previously processed records. > > To keep things simple I plan to use $done=file() to read the flat file, > and a simple if in_array to see if the current GUID has already been > processed, if not process the current record and add its GUID to $done. > > Does anyone know if sorting an array has any significant impact on > in_array, or can I simply push push values into $done? > > Also is there a better way than foreach() write() to get $done back into > the flat file? > Arrays in PHP are associative; their keys are handled as hash values. So I suspect it makes no difference on whether the array is sorted or not. Also, what's wrong with foreach() write()? That's how you get arrays back into a file. Ensure you lock the file so that you don't have two scripts running against it at the same time. But it sounds like you should be using a database. That would solve a lot of your problems. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
in_array performance in unsorted vs sorted array William Gill <noreply@domain.invalid> - 2012-05-23 02:20 -0400
Re: in_array performance in unsorted vs sorted array Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-23 08:16 -0400
Re: in_array performance in unsorted vs sorted array William Gill <noreply@domain.invalid> - 2012-05-23 10:57 -0400
Re: in_array performance in unsorted vs sorted array William Gill <noreply@domain.invalid> - 2012-05-23 11:01 -0400
Re: in_array performance in unsorted vs sorted array Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2012-05-24 22:20 +0200
Re: in_array performance in unsorted vs sorted array Captain Paralytic <paul_lautman@yahoo.com> - 2012-05-23 02:36 -0700
csiph-web