Match using nGram

Hi,

I am doing a string similarity based on NGram approach
I have two arrays $receive1 and $receive2. I need to compare each element of these two array using nGram .
Match = number of ngrams that are common/maximal number of n grams for the word

the function getNgrams works fine but i am stuck on matching part.
Could you advise me on this.

here is my code:

function getNgrams($match, $n = 3) {

            $ngrams = array();
            $len = strlen($match);
            for($i = 0; $i < $len; $i++) {
                    if($i > ($n - 2)) {
                            $ng = '';
                            for($j = $n-1; $j >= 0; $j--) {
                                    $ng .= $match[$i-$j];
                            }
                            $ngrams[] = $ng;
                    }

            }
            return $ngrams;

    }

for($i=0;$i<count($receive1);$i++)
{
for($i=0;$i<count($receive2);$i++)
{
$array1=getNgrams($receive1[$i]);
$array2=getNgrams($receive1[$j]);
$common=array_intersect($array1,$array2);

}
}

it is solved now.