【问题标题】:Extending Gravity Forms Personality Quiz to determine multiple results扩展重力形式个性测验以确定多个结果
【发布时间】: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


【解决方案1】:

您可能已经知道这一点,但快速浏览一下,您似乎有一些语法错误。

例如: $scoress($$quiz_questions, "公斤") 应该 $scores($quiz_questions, "公斤")

【讨论】:

  • 感谢您发现@Rochelle 在复制时一定犯了这些错别字。我现在已经更新了代码。
猜你喜欢
  • 1970-01-01
  • 2021-08-10
  • 2012-11-15
  • 2016-12-26
  • 1970-01-01
  • 2013-11-25
  • 2014-07-21
  • 1970-01-01
  • 2014-09-13
相关资源
最近更新 更多