How can I use a variable in cosine similarity function?
<p>I am using cosine similarity to compare the contents of two web pages.
I am getting the contents of the web pages into two variables. </p>

<pre><code>$my_var1 = file_get_contents('http://www.website1.com');
$my_var2 = file_get_contents('http://www.website2.com');
$sim = new CosineSimilarity();
$sim-&gt;similarity($my_var1,$my_var2);
</code></pre>

<p>Then I need to use this in the similarity function:</p>

<pre><code>class CosineSimilarity {
public function similarity(array $vec1, array $vec2) {
    $value = $this-&gt;_dotProduct($vec1, $vec2) / ($this-&gt;_absVector($vec1) * $this-&gt;_absVector($vec2));
echo "The similarity is";   
echo $value;    
}



protected function _dotProduct(array $vec1, array $vec2) {
$result = 0;
    foreach (array_keys($vec1) as $key1) {
        foreach (array_keys($vec2) as $key2) {
        if ($key1 === $key2) $result += $vec1[$key1] * $vec2[$key2];
            }
        }
        return $result;
}
protected function _absVector(array $vec) {
        $result = 0;
    foreach (array_values($vec) as $value) {
            $result += $value * $value;
        }
        return sqrt($result);
}

}
</code></pre>

<p>How can I use the variables as array elements in the function?
Thank you!</p>
