FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » in_array performance in unsorted vs sorted array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: in_array performance in unsorted vs sorted array [message #178205 is a reply to message #178204] Wed, 23 May 2012 12:16 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
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(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Windows binaries 64bit for PHP
Next Topic: On the usage of "@" (error control operator)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 01:06:19 GMT 2024

Total time taken to generate the page: 0.03495 seconds