我的函数有两个函数。php
这两个函数都来自一个插件,我试图在另一个操作中使用这个变量$answerIndex来执行if条件。
问题是我正在尝试全局变量,但它不起作用,我是否做错了什么?
add_action(\'quiz_completed\', \'mi_ld_quiz_ert\', 10, 2);
function mi_ld_quiz_ert( $quizdata, $current_user ) {
global $globalres;
if($globalres== 0){
do_action(\'ld_update_group_access\', $current_user, 2, $remove = false ));
}else{
do_action(\'ld_update_group_access\', $current_user, 14, $remove = false ));
}
}
add_action(\'learndash_ques_single_answer_correct\', \'my_ld_quiz_resp\',5,5);
function my_ld_quiz_resp( $answerIndex, $correctAnswer, $userResponse) {
global $globalres;
$globalres = $answerIndex;
}
首先运行操作my\\u ld\\u quick\\u resp,然后运行mi\\u ld\\u quick\\u ert。
SO网友:MarkV-2
Try
$globalres = \'\';
add_action(\'quiz_completed\', \'mi_ld_quiz_ert\', 10, 2);
function mi_ld_quiz_ert( $quizdata, $current_user ) {
global $globalres;
if($globalres== 0){
do_action(\'ld_update_group_access\', $current_user, 2, $remove = false ));
}
else{
do_action(\'ld_update_group_access\', $current_user, 14, $remove = false ));
}
}
add_action(\'learndash_ques_single_answer_correct\', \'my_ld_quiz_resp\',5,5);
function my_ld_quiz_resp( $answerIndex, $correctAnswer, $userResponse) {
global $globalres;
$globalres = $answerIndex;
}