How to add an array inside another array? I have these 2, I want to add the below in the top, with the name "answers"
Array
(
[0] => Array
(
[id] => 0
[unidade] => 4
[exercicio] => 1
[enunciado] => Complete with the correct pronoun
[pergunta] => Marcus and his brother talk about politics between ???
[imagem] =>
[tipo] => complete1
[respostacorreta] => themselves
)
[] => Array
(
[0] => They
[1] => Them
[2] => Themselves
)
)
My final result in json should look something like:
{
"0": {
"id": "0",
"unidade": "4",
"exercicio": "1",
"enunciado": "Complete with the correct pronoun",
"pergunta": "Marcus and his brother talk about politics between ???",
"imagem": null,
"tipo": "complete1",
"respostas": [
"They",
"Them",
"Themselves"
],
"respostacorreta": "themselves"
}
}
My current code looks like this:
$sql = new Sql();
$exercicioarray = $sql->select("SELECT * FROM tb_exercicios");
$arrayrespostas = explode(',',$exercicioarray[0]['respostas']);
unset($exercicioarray[0]['respostas']);
$exercicioarraysemresposta = $exercicioarray;
$exercicioarraycomresposta = $exercicioarraysemresposta[$exercicioarraysemresposta[0]['respostas']] = $arrayrespostas;
//print_r($exercicioarraysemresposta);
//print_r($arrayrespostas);
$response = json_encode($exercicioarraysemresposta, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);