| |||||||||||
| |||||||||||
Deleting duplicates from an array Posted by Chris_Isaac (Chris Isaac), 18 June 2003 HiI'm trying to delete duplicate values from an array. 1st I'm pulling 2 varibles together (town and county fields), themn putting into an array, but the array_unique function is failing. The output says it must be an array. I've tried various options... help... please.... ![]() Thanks Chris Code:
Posted by admin (Graham Ellis), 18 June 2003 Can I paraphrase the question to make sure I understand it? You have an arrayt containing a town and a county, and you want to eliminate one of them if they're both the same. ThusMelksham Wiltshire will remain as a two element array but London London would be reduced to a single element. I think this is the sort of thing you need to do: Code:
I'm not 100% sure I followed the question right ... so I haven't put in the time to test this / develop a working demo. Let me know whether this is the solution you need or if I'm not on track. Posted by Chris_Isaac (Chris Isaac), 18 June 2003 HiNot quite, I'm pulling the town/county fields out of a table which has multiple entryies for the same town county, eg: chris 123 Bloggs street, Newport, Gwent Nicky 234 You Street, Newport, IOW fred 543 Cindy Street, Newport, Gwent so when I pullout the Town/County I would get: Newport, Gwent Newport, IOW Newport, Gwent from this I only want 1 entry for Newport, Gwent. and 1 entry for Newport IOW. Hope this makes sense. Chris Posted by admin (Graham Ellis), 18 June 2003 OK ... then within your while loop that fetched the data, you want to make up the $combined variable as it was in the code you originally posted. But don't print it out ... instead, array_push it onto an array (let's call it $towns for the sake of argument.Outside (after) the loop: Code:
p.s. remember that before you push onto an array, it must already exist. Create it with $towns = array(); Posted by Chris_Isaac (Chris Isaac), 19 June 2003 Hi, sorry, I'm still having trouble. If I run the script below, $towns[0] in the while loop just prints out Array for each entry. $towns[0] after the array_unique just has 1 entry. I've tried putting that in a foreach loop but it doesn't change.chris Code:
Posted by admin (Graham Ellis), 19 June 2003 Oops - you don't want to make each $combined into an array; afraid my comment in the previous post was a bit misleading. Make up the string of the town and county as just an ordinary variable and array_push it ... then it should work. Posted by Chris_Isaac (Chris Isaac), 19 June 2003 Perfect, thankyou. ![]() This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |