【发布时间】:2020-12-15 13:55:03
【问题描述】:
我正在为 Gravity Forms 使用 Personality Quiz 插件,并希望扩展它的功能。目前,它会像这样确定多项选择测验的“获胜者”:
$scores = array_count_values( $quiz_questions );
$winners = array_keys( $scores, max( $scores ), true );
return $winners[0];
与其简单地返回哪个选项(A、B 或 C)获得了最多的点击,我更愿意使用分数范围,这样如果“A”> 30 则 $winners 将是“Type 1”,如果“ A">20 和 "B">20 $winners 将是 "Type 2",如果 "B">20 和 "C">20 $winners 将是 "Type 3",等等。我一直在尝试这个的变体但没有发现错误。
$scores = array_count_values( $quiz_questions );
$k_count_total = count($scores($quiz_questions, "Kilo"));
$v_count_total = count($scores($quiz_questions, "Victor"));
$p_count_total = count($scores($quiz_questions, "Papa"));
if ($v_count_total > 33) { $winners = "Victor"; }
elseif ($v_count_total > 17 && $p_count_total > 17) {$winners = "Victor-Papa";}
elseif ($v_count_total > 17 && $k_count_total > 17) {$winners = "Victor-Kilo";}
elseif ($p_count_total > 33) {$winners = "Papa";}
elseif ($p_count_total > 17 && $k_count_total > 17) {$winners = "Papa-Kilo";}
elseif ($k_count_total > 33) {$winners = "Kilo";}
elseif ($k_count_total > 15 && $v_count_total > 15 && $p_count_total > 15) {$winners = "VPK";}
return $winners[0];
【问题讨论】:
-
为什么把半天前已经问的问题删了? stackoverflow.com/q/65298775/1427878
-
“但到目前为止还没有运气” - 有了那个,你也不太可能有更多的运气。请阅读How to Ask。
-
谢谢@CBroe 我已经更新了问题
标签: php wordpress gravityforms