2014-02-20 70 views
1

這裏是我的歐幾里德方程的furmula實現。在PHP中應用歐幾里得距離公式

$i = 0; 
    $min = 0; 

    while ($row = @mysqli_fetch_array($result)) 

    { 

     $pcount = $row['pcount']; 

     $ncount = $row['ncount']; 

     echo "pcount is $pcount<br/>"; 

     echo "ncount is $ncount<br/></br>"; 
     $a[$i] = $pcoutn ; 
     $b[$i] = $pcoutn ; 
     while ($row = @mysqli_fetch_array($result)) 

     { 

      $a[$j] = $row['pcount']; 
      $b[$j] = $row['ncount']; 
      $diff = sqrt(($a[$i] - $a[$j])^2 + ($b[$i] - $b[$j])^2) 
      $j= $j + 1; 
      echo "$diff <br>"; 
     }    
     $i = $i + 1;   


    } 

什麼是語法錯誤?

錯誤是:Parse error: syntax error, unexpected '$j' (T_VARIABLE)

+3

你缺少後'$ DIFF =開方分號(($ A [$ I ] - $ a [$ j])^ 2 +($ b [$ i] - $ b [$ j])^ 2)' –

+1

'^'是['xor'](http://www.php .net/manual/language.operators.bitwise.php)運算符。所以即使沒有語法錯誤,你的endresult也會出錯。改用['pow'](http://php.net/manual/function.pow.php)。 – Yoshi

回答

1

你就行跳過;

$diff = sqrt(($a[$i] - $a[$j])^2 + ($b[$i] - $b[$j])^2) 

使用

$diff = sqrt(($a[$i] - $a[$j])^2 + ($b[$i] - $b[$j])^2);