数组到字符串转换,比较数组

时间:2017-07-19 19:27:41

标签: php laravel

您好我需要比较这两个数组$answers_selected$correct_answer,但第一个数组显示错误

  

数组到字符串转换

请有人帮助我,我是laravel的新人..?这是代码:

$answers_selected = $request->except('_token', 'test_id');
foreach($questions as $question){

    $answers = Answer::where('question_id', $question->id)

                    ->where('deleted',0)
                    ->get()->toArray();

    foreach($question->answers as $answer){

        $correct_answer = Answer::where('id', $answer->id) 
                                ->where('correct', 1)
                                ->where('deleted',0)
                                ->get()->toArray();

        if(count($correct_answer) == 1){
            $answer_result = 1;
        }
        else{
            $answer_result = 0;
        }

    } 
    $result = array_diff($answers_select, $correct_answer);

    return view('website.questions.partials.multiplechoice.prov')
                ->with(['request' =>  $result]);

    }

0 个答案:

没有答案