算术计算器编码总是0

时间:2016-06-23 11:01:06

标签: php

大家好,我正在编写一个计算器,但无论我的代码是什么,我得到的结果总是0:

<?php
function sortBySpeed($a, $b) {
    return $b['Speed'] - $a['Speed'];
}


if(isset($_POST["submit"])){

    $ninjas = array( array( 
                      'Name' => "Main", 
                      'Damage' => $_POST["dmg1"],
                      'Damagerate' => $_POST["dmgrate1"],
                      'Damagegrow' => $_POST["dmggrow1"],
                      'Speed' => $_POST["speed1"],
                      'Fury' => 50
                    ),
                array( 
                      'Name' => $_POST["ninja2"], 
                      'Damage' => $_POST["dmg2"],
                      'Damagerate' => $_POST["dmgrate2"],
                      'Damagegrow' => $_POST["dmggrow2"],
                      'Speed' => $_POST["speed2"],
                      'Fury' => 50
                    ),
                array( 
                      'Name' => $_POST["ninja3"], 
                      'Damage' => $_POST["dmg3"],
                      'Damagerate'=> $_POST["dmgrate3"],
                      'Damagegrow' => $_POST["dmggrow3"],
                      'Speed' => $_POST["speed3"],
                      'Fury' => 50
                    ),
                array( 
                      'Name' => $_POST["ninja4"], 
                      'Damage' => $_POST["dmg4"],
                      'Damagerate' => $_POST["dmgrate4"],
                      'Damagegrow' => $_POST["dmggrow4"],
                      'Speed' => $_POST["speed4"],
                      'Fury' => 50
                    ),
                array( 
                      'Name' => $_POST["ninja5"], 
                      'Damage' => $_POST["dmg5"],
                      'Damagerate' => $_POST["dmgrate5"],
                      'Damagegrow' => $_POST["dmggrow5"],
                      'Speed' => $_POST["speed5"],
                      'Fury' => 50
                    )
             );


    $totaldmg = 0;
    $damagerate = 0;
    $damagegrow = 0;
    $furydmg = 0;

    usort($ninjas, 'sortBySpeed');  
    for($x = 0; $x < 6; $x++){
        for($a = 0; $a < 5; $a++){
            if($ninjas[$a]["Name"] == "Kabuto" && $x > 0){
                for($b = 0; $b < 5; $b++){
                    $ninjas[$b]["Fury"] +=25;
                }

                if($ninjas[$a]["Fury"] == 100){
                    $damagerate == $ninjas[$a]["Damage"]/100*$ninjas[$a]["Damagerate"];
                    $damagegrow == $damagerate/100*$ninjas[$a]["Damagegrow"];
                    $totaldmg += $damagegrow;
                    $ninjas[$a]["Fury"] == 0;
                }else if($ninjas[$a]["Fury"] > 100){
                    $damagerate == $ninjas[$a]["Damage"]/100*$ninjas[$a]["Damagerate"];
                    $damagegrow == $damagerate/100*$ninjas[$a]["Damagegrow"];
                    $furydmg == $damagegrow + ($damagegrow/100)*(($ninjas[$a]["Fury"]-100)/0.25);
                    $totaldmg += $damagegrow;
                    $ninjas[$a]["Fury"] == 0;
                }else{
                    $ninjas[$a]["Fury"] +=50;
                    $damagerate == $ninjas[$a]["Damage"]/100*$ninjas[$a]["Damagerate"];
                    $totaldmg += $damagerate;
                }

            }else{
                if($ninjas[$a]["Fury"] == 100){
                    $damagerate == $ninjas[$a]["Damage"]/100*$ninjas[$a]["Damagerate"];
                    $damagegrow == $damagerate/100*$ninjas[$a]["Damagegrow"];
                    $totaldmg += $damagegrow;
                    $ninjas[$a]["Fury"] == 0;
                }else if($ninjas[$a]["Fury"] > 100){
                    $damagerate == $ninjas[$a]["Damage"]/100*$ninjas[$a]["Damagerate"];
                    $damagegrow == $damagerate/100*$ninjas[$a]["Damagegrow"];
                    $furydmg == $damagegrow + ($damagegrow/100)*(($ninjas[$a]["Fury"]-100)/0.25);
                    $totaldmg += $damagegrow;
                    $ninjas[$a]["Fury"] == 0;
                }else{
                    $ninjas[$a]["Fury"] +=50;
                    $damagerate == $ninjas[$a]["Damage"]/100*$ninjas[$a]["Damagerate"];
                    $totaldmg += $damagerate;
                }
            }
        }
    }

    echo $totaldmg;

}

?>

所以我做了一个表格,其中用户输入所有数组数据的值然后尝试计算所有忍者每6次战斗的总伤害有5个忍者所以我做了一个for循环(6战斗)然后在里面循环(5 ninjas)并做一些计算,但我总是得到0,也许有人知道我在哪里犯了错误

1 个答案:

答案 0 :(得分:0)

My bad should use = when giving a new meaning not ==