RE: Hot array problem: Strip off redundant elements

From: Date: Wed, 29 Nov 2000 00:33:07 +0000
Subject: RE: Hot array problem: Strip off redundant elements
Groups: php.general 
Request: Send a blank email to php-general+get-27726@lists.php.net to get a copy of this message
---------------------------------------------------------------------------- ----------------- Disclaimer: The information contained in this email is intended only for the use of the person(s) to whom it is addressed and may be confidential or contain legally privileged information. If you are not the intended recipient you are hereby notified that any perusal, use, distribution, copying or disclosure is strictly prohibited. If you have received this email in error please immediately advise us by return email at postmaster@normandy.com.au and delete the email document without making a copy. ---------------------------------------------------------------------------- ----------------- Another way of looking at it is setting a key to be the unique value... You may currently do: $ary = array("my","my","why","why","do","i","stutter","stutter"); or $ary[] = "my"; $ary[] = "my"; $ary[] = "why"; $ary[] = "why"; $ary[] = "do"; $ary[] = "i"; $ary[] = "stutter"; $ary[] = "stutter"; Try $ary1["my"] = true; // Of course true may be some other piece of non unique info like a price, colour or whatever. $ary1["my"] = true; $ary1["why"] = true; $ary1["why"] = true; $ary1["do"] = true; $ary1["i"] = true; $ary1["stutter"] = true; $ary1["stutter"] = true; now try echo "Non unique keys"; while(list($key,$value) = each($ary)){ echo "KEY $key VALUE $value<br>\n"; } echo "Unique keys"; while(list($key,$value) = each($ary1)){ echo "KEY $key VALUE $value<br>\n"; } Using keys is exeeding handy if you want to store an array of products and the amount required.. ie: a shopping list.. it also makes finding the info you need a lot easier as you dont have to parse the whole array. mn Mark Nold markn@enspace.com <mailto:markn@enspace.com> Senior Consultant   Change is inevitable, except from vending machines. -----Original Message----- From: Juergen Hall [mailto:jyrgen@gmx.de] Sent: Tuesday, November 28, 2000 7:06 PM To: php-general@lists.php.net Subject: Hot array problem: Strip off redundant elements hi, i need a smart way to get rid of redundant elements in an array, without doing too much loops. thanks again jyrgen

« previous php.general (#27726) next »