b00ker_b0y Posted October 3, 2007 Share Posted October 3, 2007 Hello people! need to some how remove a duplicate entry to an array to an extent. ie the conents of Array1 would be something like: 0 -> Free Willy 1 -> Willy Free so both entries will be classed as the same via the words being jumbled up. So plan was to explode the words into another array and some how compare them using array_unique() maybe? getting lost in thought! any help would be gateful! Thanks Quote Link to comment Share on other sites More sharing options...
jaymc Posted October 3, 2007 Share Posted October 3, 2007 $beansarray = 0 -> a 1 -> b 2 -> c $cheesesarray = 0 -> lol 1 -> b 2 -> hey foreach ($cheesearray as $cheesearray) { if (in_array($cheesearray, $beansarray)) { echo "$cheesearray is inside the beansarray} } This would show b is inside the beansarray Quote Link to comment Share on other sites More sharing options...
shocker-z Posted October 3, 2007 Share Posted October 3, 2007 I found this code that seems to work function goFindDuplicates($lcArray) { array_walk($lcArray, 'lcArrayVal'); //lowercase all the values first $uniqueArray = array_unique($lcArray);//only unique values $dupArray = array_diff_assoc($lcArray, $uniqueArray);//duplicated values foreach ($dupArray as $value) { //do whatever you want here like build an assoc array. echo "duplicate value='$value', first occurence at index=" . array_search($value,$lcArray) . "\n"; } } function lcArrayVal(&$item, $key) { $item = strtolower($item); } Regards Liam Quote Link to comment Share on other sites More sharing options...
b00ker_b0y Posted October 3, 2007 Author Share Posted October 3, 2007 hey. jaymc - that will only work for 2 arrays won't it? how would you go about adapting that to take an unlimited number of arrays. shocker-z - what exactly does that function(s) do? cheers for your help lads Quote Link to comment Share on other sites More sharing options...
b00ker_b0y Posted October 3, 2007 Author Share Posted October 3, 2007 shocker-z - cheers for the reply but its not realy what i am looking for. array_unique() bascily does that. its not realy a duplicate as such, just need to compare the words in phrases but in a muddled order. so need it to flag up these as being the same for example: Hello the world the world hello world hello the cheers for the quick reply none the less Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.