我需要將此代碼轉換爲PHP的幫助。將JavaScript代碼轉換爲PHP
var formula = [10,6.7,3.4];
var user1 = [1,0,2,1,1,0,2,2,2,2];
var user2 = [2,1,2,0,1,2,2,2,0,0];
var result = 0;
calculate();
function calculate(){
for(var i=0; i<user1.length; i++){
result +=formula[Math.abs(user1[i]-user2[i])]
}
}
alert(result);
PHP代碼:
<?php
$formula = array(10,6.7,3.4);
$user1 = array(1,0,2,1,1,0,2,2,2,2);
$user2 = array(2,1,2,0,1,2,2,2,0,0);
$result = 0;
function calculate(){
for($i=0, $size = count($user1); $i<$size; $i++){
$result += $formula(abs($user1[$i]-$user2[$i]));
}
}
calculate();
echo $result;
?>
PHP代碼不起作用。請幫幫我。
是否有錯誤訊息? –