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

Home » Imported messages » comp.lang.php » use of array_key_exists() to prevent duplicates?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: use of array_key_exists() to prevent duplicates? [message #173014 is a reply to message #173013] Thu, 17 March 2011 15:58 Go to previous messageGo to previous message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma:
Senior Member
On Mar 17, 3:35 pm, William Gill <nos...@domain.invalid> wrote:
> I have a very simple app that I am working on.  I have input files
> containing records with a unique serial number followed by a short (<255
> char) memo.  The source program duplicates records from previous runs,
> along with any new records.  I want to create a result file w/o
> duplicates.  I am thinking of reading the files into an array where
> serial number becomes the key and memo the value, using
> array_key_exists() to filter out duplicates.   The source files are no
> more than a couple hundred records each, and the master should never
> exceed a couple thousand.
>
> Does anybody see any drawbacks to this, or have a better approach?
>
> Thanks,
>
> Bill

Alternative 1) Just assign the values to an associative array with the
serial number as the key. At the end a foreach will produce a list of
unique values. No need for array_key_exists() at all.

Alternative 2) If you are planning on storing the data in a database
just use INSERT IGNORE.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Php Modal
Next Topic: Pipe the content of a variable to a process
Goto Forum:
  

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

Current Time: Thu Nov 28 12:15:14 GMT 2024

Total time taken to generate the page: 0.04670 seconds