我需要这个变量来查看比较

时间:2017-08-03 08:34:30

标签: php laravel view foreach blade

我有这段代码

dd($correct_question);

到目前为止,当我尝试使用@foreach($test_questions as $question) @foreach ($test_results as $question_result) @if($correct_question) <i id="checki" class="fa fa-check"></i> @else <i id="remove" class="fa fa-remove"></i> @endif @endforeach @endforeach 时它会很好,它会告诉我它是否正确,但我希望在视图中显示我有这个视图

return view('website.tests.take.take-test-results')->with([
    'results'          => $test_results,
    'test_questions'   => $test_questions,
    'correct_question' => $correct_question,
]);

我不知道怎么用这样的东西发送到视图或者我不知道有人可以帮助我..?谢谢。

    wp_register_script('dataTables.min.js', 'https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js', array('jquery'), true);

    wp_register_script('customjs.js', get_template_directory_uri() . '/js/customjs.js', array('jquery'), true);
    wp_enqueue_script('customjs.js');
    wp_enqueue_style('dataTables.min.css');
    wp_enqueue_style('buttons.dataTables.min.css');

2 个答案:

答案 0 :(得分:0)

您可以按照以下步骤操作:

 @foreach ($test_results as $question_result)
    @if($question_result == 1)
        <i id="checki" class="fa fa-check"></i> 
    @else
        <i id="remove" class="fa fa-remove"></i>
    @endif
@endforeach

答案 1 :(得分:0)

尝试以下代码:

@foreach($test_questions as $question)
    @if(in_array($question, $correct_question))
        <i id="checki" class="fa fa-check"></i> 
    @else
        <i id="remove" class="fa fa-remove"></i>
    @endif
@endforeach

注意:如果您的$question有ID且您的$correct_question有正确的问题/答案,您可以尝试@if(in_array($question['id'], $correct_question))