Combine 2 matrizes combinando a mesma chave estrangeira
Eu tenho 2 tabelas, que é uma tabela de perguntas e uma tabela de respostas, a estrutura é assim:
E eu tenho uma matriz JSON que obtive de question_table e answer_table usando php como est
// to get the question
$pertanyaan = "select * from question_table”;
$resultPertanyaan = mysqli_query($con, $pertanyaan);
while($rowQuery= mysqli_fetch_array($resultPertanyaan)){
$array_question[]=
array('id'=>$rowQuery['id’],’question’=>$rowQuery['question']);
}
e o resultado é assim
array_question :
[
{
"id": "8",
“question”: "Shop sign/billboard "
},
{
"id": "10",
"question": "Pylon"
},
{
"id": “11”,
“question”: "Banner”
},
{
"id": "12”,
"question": “Sport”
},
{
"id": “14”,
“question”: “Matic "
},
{
"id": "16”,
"question": “Cub”
}
]
Para obter a resposta
$jawaban = "select * from answer_table”;
$resultJawaban = mysqli_query($con, $jawaban);
while($rowQuery= mysqli_fetch_array($resultJawaban)){
$array_answer[]=
array('id'=>$rowQuery['id'],'remark'=>$rowQuery['remark'],'item'=>$rowQuery['item']);
}
e o resultado assim
array_answer :
[
{
"id": "1b9fa84e-0f2f-11e9-b673-005056be36b2",
“answer”: "3",
“id_question”: "16"
},
{
"id": "bc82c3fd-0f2e-11e9-b673-005056be36b2",
"answer": "1",
"id_question": "11"
},
{
"id": "cc9363f1-0f2e-11e9-b673-005056be36b2",
"answer": "3",
"id_question": "12"
},
{
"id": "f1dfa8b5-0f2e-11e9-b673-005056be36b2",
"answer": "1",
"id_question": "14"
}
]
Eu quero combinar array_answer com array_question, que resulta desta forma:
array_result :
[
{
"id": "8",
“question”: "Shop sign/billboard ",
“asnwer” : null
},
{
"id": "10",
"question": "Pylon”,
“asnwer” : null
},
{
"id": “11”,
“question”: "Banner”,
“asnwer” : “1”
},
{
"id": "12”,
"question": “Sport”,
“answer” : “3”
},
{
"id": “14”,
“question”: “Matic “,
“answer” : “1”
},
{
"id": "16”,
"question": “Cub”,
“answer” : “3”
}
]
Como obtenho array_result como eu esperava? Por favor me ajude, obrigad