Jump to content

Duplication - Array in an Array?


b00ker_b0y

Recommended Posts

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

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.