我需要帮助将此代码转换为 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 代码不起作用。请帮帮我。