Include “required questions” in a random selection

后端 未结 2 1043
情深已故
情深已故 2021-01-18 05:16

I\'m selecting a set of random questions without any duplicates using the following:



        
2条回答
  •  天涯浪人
    2021-01-18 05:30

    First you need to filter out the required questions like so:

    $all_questions = get_field("step_by_step_test");
    $required = $optional = array();
    foreach($all_questions as $question) {
        if( $a['required_question']) $required[] = $question;
        else $optional[] = $question;
    }
    $amount = get_field("select_number_of_questions")-count($required);
    shuffle($optional);
    $final = array_merge($required,array_slice($optional,0,$amount));
    foreach($final as $repeater_row) {
        ...
    }
    

    Hope I helped you again :p

提交回复
热议问题