Re: Im seeking a solution to check for duplicate entries with an other sequence

From: Date: Tue, 12 Jan 2010 16:33:23 +0000
Subject: Re: Im seeking a solution to check for duplicate entries with an other sequence
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-46774@lists.php.net to get a copy of this message
2010/1/11 Richard Quadling <rquadling@googlemail.com>: > 2010/1/11 omar zorgui <omarzorgui@gmail.com>: >> $sentences[] = "this is a example sentence"; >> $sentences[] = "a this is example sentence"; >> $sentences[] = "example this is a sentence"; >> $sentences[] = "this is a example sentence for a function"; > > > <?php > // Define data. > $Sentences = array >        ( >        "this is a example sentence", >        "a this is example sentence", >        "example this is a sentence", >        "this is a example sentence for a function", >        ); > > // Record hashes of the sorted words in each sentence. > $Hashes = array(); > $Reduced = array_filter >        ( >        $Sentences, >        function($Sentence) >                use(&$Hashes) >                { >                // Explode the sentence into words but forced to lower case. >                $Words = explode(' ', strtolower($Sentence)); > >                // Sort the words >                sort($Words); > >                // If the hash of the serialized words array is not already known >                if (!in_array($Hash = md5(serialize($Words)), $Hashes)) >                        { >                        // then add it and return true. >                        $Hashes[] = $Hash; >                        return True; >                        } >                else >                        { >                        // else return false to filter out this sentence. >                        return False; >                        } >                } >        ); > > // Show the reduced sentences. > print_r($Reduced); > ?> > > > outputs ... > > Array > ( >    [0] => this is a example sentence >    [3] => this is a example sentence for a function > ) > > > > -- > ----- > Richard Quadling > "Standing on the shoulders of some very clever giants!" > EE : http://www.experts-exchange.com/M_248814.html > Zend Certified Engineer : > http://zend.com/zce.php?c=ZEND002498&r=213474731 > ZOPA : http://uk.zopa.com/member/RQuadling > Is that what you wanted? -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling

« previous php.db (#46774) next »