Re: array_unique() workaround? SOLUTION!

From: Date: Wed, 14 Nov 2001 13:06:45 +0000
Subject: Re: array_unique() workaround? SOLUTION!
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-74591@lists.php.net to get a copy of this message
reset() is not needed when using foreach but is requirement when using : each(),next(),prev(), etc. Andrey Hristov IcyGEN Corporation http://www.icygen.com BALANCED SOLUTIONS ----- Original Message ----- From: "dav" <dav@thecloud.o> To: <php-general@lists.php.net> Sent: Wednesday, November 14, 2001 3:08 PM Subject: Re: [PHP] array_unique() workaround? SOLUTION! > Well infact you are checking equity, like my suggestion about in_array :-) > "Spunk S. Spunk III" <spunk@mac.com> ha scritto nel messaggio > news:B817FAFF.E7B6%spunk@mac.com... > > Thanks everyone for the ideas, > > Here's what I came up with... > > I forgot to mention that I needed to preserve the original array's keys. > > Here is a replacement I wrote that seems to work. Let me know if you see > > errors in it or have improvements. > > > > function my_array_unique($somearray) > > { > > asort($somearray); > > reset($somearray); > > $currentarrayvar = current($somearray); > > foreach ($somearray as $key=>$var) > > { > > if (next($somearray) != $currentarrayvar) > > { > > $uniquearray[$key] = $currentarrayvar; > > $currentarrayvar = current($somearray); > > } > > } > > reset($uniquearray); > > return $uniquearray; > > } > > > > > > > > > > I'm working on a script that needs array_unique() but my host is using > 4.0.4 > > > and it's broken in that build. Does anyone have a good workaround for > this? > > > I can wait for my host to upgrade but if I release this code, it would > be > > > better to have the workaround... > > > > > > I just need a good way to check for dups in an array and remove them. I > > > can't get my brain around it... > > > > > > TIA > > > Spunk > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-general-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#74591) next »