Php 从人格测试中获得准确的结果

Php 从人格测试中获得准确的结果,php,jquery,ajax,Php,Jquery,Ajax,这个代码有什么问题,需要想法谢谢。 我使用了另一种对我来说很好的方法,但我的团队负责人说这不好,因为我们需要一个匹配的用户输入结果,以便在提交后回显。所以我想出了类似的办法。但还是不行 <?php //One of this should be my Results after input submited. $type = array( 0 => array(

这个代码有什么问题,需要想法谢谢。 我使用了另一种对我来说很好的方法,但我的团队负责人说这不好,因为我们需要一个匹配的用户输入结果,以便在提交后回显。所以我想出了类似的办法。但还是不行

 <?php
            //One of this should be my Results after input submited.
                $type = array(
                    0 => array(
                        "val" => 0,
                        "title" => "Du bist Weltenbummler"
                    ),
                    1 => array(
                        "val" => 0,
                        "title" => "Luxusliebhaber"
                    ),
                    2 => array(
                        "val" => 0,
                        "title" => "Naturbursche/-madle"
                    ),
                    3 => array(
                        "val" => 0,
                        "title" => "Sunnyboy/-girl"
                    ),
                    4 => array(
                        "val" => 0,
                        "title" => "Wasserratte"
                    ),
                    5 => array(
                        "val" => 0,
                        "title" => "Wellnessliebhaber"
                    ),
                    6 => array(
                        "val" => 0,
                        "title" => "Adrenalinjunkie"
                    ),
                    7 => array(
                        "val" => 0,
                        "title" => "Städtebummler"
                    )
                );

    //this are my post data which is being looped to store the user input value
            $type = "";
            $current = 0;
            $exp = explode(',', $_POST['expenditure']);
           foreach($exp as $key => $arrE){
                $arrEx = $arrE;
               if($arrE < 300) {
                   $type[0]["val"] += 0;
                   $type[1]["val"] += 0.1;
                   $type[2]["val"] += 0.4;
                   $type[3]["val"] += 0.3;
                   $type[4]["val"] += 0.7;
                   $type[5]["val"] += 1;
                   $type[6]["val"] += 0.7;
                   $type[7]["val"] += 1;

               }
                if($arrEx >= 300 && $arrEx <= 500) {
                   $type[0]["val"] += 0;
                   $type[1]["val"] += 1;
                   $type[2]["val"] += 0.4;
                   $type[3]["val"] += 1;
                   $type[4]["val"] += 0.7;
                   $type[5]["val"] += 1;
                   $type[6]["val"] += 0.7;
                   $type[7]["val"] += 1;

               }   
                  if($arrEx >= 600 && $arrEx <= 800) {
                   $type[0]["val"] += 1;
                   $type[1]["val"] += 1;
                   $type[2]["val"] += 0.4;
                   $type[3]["val"] += 1;
                   $type[4]["val"] += 0.7;
                   $type[5]["val"] += 1;
                   $type[6]["val"] += 0.7;
                   $type[7]["val"] += 1;

               } 
               if($arrEx >= 900 && $arrEx <= 1000) {
                   $type[0]["val"] += 2;
                   $type[1]["val"] += 1.4;
                   $type[2]["val"] += 0.4;
                   $type[3]["val"] += 1;
                   $type[4]["val"] += 0.7;
                   $type[5]["val"] += 1.3;
                   $type[6]["val"] += 1.4;
                   $type[7]["val"] += 1.5;

               }
               if($arrEx >= 1500 && $arrEx <= 3000) {
                   $type[0]["val"] += 2;
                   $type[1]["val"] += 1.4;
                   $type[2]["val"] += 0.4;
                   $type[3]["val"] += 1;
                   $type[4]["val"] += 0.7;
                   $type[5]["val"] += 1.3;
                   $type[6]["val"] += 2.2;
                   $type[7]["val"] += 2.1;

               }

           }
     $Season = explode(',', $_POST['seasonString']);
          foreach($Season as $key => $arrS){
               $arrSe = $arrS;
                if( $arrSe == "1"){
                   $type[0]["val"] += 1;
                   $type[1]["val"] += 1.4;
                   $type[2]["val"] += 0.4;
                   $type[3]["val"] += 1;
                   $type[4]["val"] += 2.0;
                   $type[5]["val"] += 2.0;
                   $type[6]["val"] += 2.0;
                   $type[7]["val"] += 2.0;} 
                if( $arrSe == "2"){
                   $type[0]["val"] += 0.5;
                   $type[1]["val"] += 1.1;
                   $type[2]["val"] += 1.4;
                   $type[3]["val"] += 1.0;
                   $type[4]["val"] += 2.0;
                   $type[5]["val"] += 2.0;
                   $type[6]["val"] += 2.0;
                   $type[7]["val"] += 2.0;}
                if( $arrSe == "3"){             
                   $type[0]["val"] += 0.5;
                   $type[1]["val"] += 1.1;
                   $type[2]["val"] += 1.4;
                   $type[3]["val"] += 1.0;
                   $type[4]["val"] += 2.0;
                   $type[5]["val"] += 2.0;
                   $type[6]["val"] += 2.0;
                   $type[7]["val"] += 2.0;}
                if( $arrSe == "4"){
                    $type[0]["val"] += 0.5;
                   $type[1]["val"] += 1.1;
                   $type[2]["val"] += 1.4;
                   $type[3]["val"] += 0.5;
                   $type[4]["val"] += 2.0;
                   $type[5]["val"] += 2.0;
                   $type[6]["val"] += 2.0;
                   $type[7]["val"] += 2.0;
                }

                }



    for($i=0;$i<count($type);$i++){
     //First loop
            if($i == 0) {
                $title = $type[0]["title"];
                $current = $type[0]["val"];
            }

            if($type[$i]["val"] > $current) {
                $title = $type[$i]["title"];
            }

    }
    echo $type;

        ?>

完全猜测

$index = 0;
$max = $type[0]["val"];

for($i=1; $i<count($type); $i++) {
    if($type[$i]["val"] > $max) {
        $index = $i;
        $max = $type[$i]["val"];
    }
}
echo "Du bist " . $type[$index]["title"];
$index=0;
$max=$type[0][“val”];
对于($i=1;$i$max){
$index=$i;
$max=$type[$i][“val”];
}
}
回音“dubist”$键入[$index][“title”];
或者更简单一点:

$maxItem = $type[0];
for($i = 1; $i < count($type); $i++) {
    if($type[$i]["val"] > $maxItem["val"]) {
        $maxItem = $type[$i];
    }
}
echo "Du bist " . $maxItem["title"];
$maxItem=$type[0];
对于($i=1;$i$maxItem[“val”]){
$maxItem=$type[$i];
}
}
回音“dubist”$maxItem[“标题”];

问题需要更好的介绍。代码应该做什么?什么不起作用?是一个个性测试,muss根据用户输入给我匹配的结果。正如我所说的,使用多维索引数组的第一个代码就是我得到的。但是第二个我认为很好,但是没有被团队接受。谢谢,但是你的代码只会给我用户的最大值,而不是“标题”,这是我的问题。我得到的是最大值,但要在页面上获得附加结果和回显是我的问题。因此,请在问题中准确说明您希望回显的内容。再次抱歉,您的代码绝对正常,工作也很完美。今天就验证一下,非常感谢。