gianghl1983
5/21/2018 - 5:13 PM

Chuyen mang ket hop sang dang key => value

 $answers = [
    ['question_id' => 1, 'option' => 'C'],
    ['question_id' => 2, 'option' => 'A'],
    ['question_id' => 3, 'option' => 'C'],
    ['question_id' => 4, 'option' => 'B'],
    ['question_id' => 5, 'option' => 'C'],
    ['question_id' => 6, 'option' => 'C'],
    ['question_id' => 7, 'option' => 'D'],
    ['question_id' => 8, 'option' => 'D']
];

//B1. Chuyen $answers ve dang 'key' ==> 'value' cho de so sanh
$ket_qua =[];
foreach ($answers as $answer ){
    $ketqua[$answer['question_id']] = $answer['option'];
}