根据id的顺序比较两个数组

时间:2017-07-31 07:16:13

标签: php arrays laravel

我有这个代码,我想根据id的顺序进行比较 这是代码:

foreach ($questions as $question) {
    $question_answers = OrderingAnswer::where('question_id', $question->id)
                            ->where('deleted', 0)
                            ->get()
                            ->toArray();

    $question_answer = $request->except('_token', 'test_id');
    $answers = $question_answer[ $question->id];

    foreach ($question_answers as $answer) {
        if ($answer === $answers) {
            $answer_result[] = 1;
        } else {
            $answer_result[] = 0;
        }
    }

    if (in_array(0, $answer_result)) {
        $question_results[$question->id] = 0;
    } else {
        $question_results[$question->id] = 1;
    }

    $answer_result = [];
    $results =  $question_results;
}

我已尝试array_diffarray_intersect但不会工作,dd($answer);的结果就是这样

array:5 [▼
  "id" => 239
  "question_id" => 239
  "text" => "something"
  "order" => 1
  "deleted" => 0
]

dd($answers);的结果就是这个

array:4 [▼
  0 => "239"
  1 => "240"
  2 => "241"
  3 => "242"
]

0 个答案:

没有答案