I need a multidimensional array that will be composed of information from the database, but I'm not able to add this information. I can not explain very well, so I'll show you.
As soon as I want it:
Array
(
[0] => Array
(
[valor_apostado] => 100
[valor_final] => 817
[id_aposta] => 1022
[0] => Array
(
[timeApostado] => Motherwell
[partidaApostada] => Motherwell x Hearts
)
[1] => Array
(
[timeApostado] => Hearts
[partidaApostada] => Pandora x Hearts
)
)
)
But it comes like this:
Array
(
[0] => Array
(
[valor_apostado] => 100
[valor_final] => 817
[id_aposta] => 1022
[0] => Array
(
[timeApostado] => Motherwell
[partidaApostada] => Motherwell x Hearts
)
)
The other part of the array inside the array is not displayed.
My code:
$idAnt = 0;
$array = "";
$i = 0;
$n = 0;
while($dado = $pegar->fetch(PDO::FETCH_ASSOC)) {
$valor_apostado = $dado["valor_apostado"];
$valor_final = $dado["valor_final"];
$tipo_aposta = $dado["tipo_aposta"];
$time = $dado["nome_time"];
$idAposta = $dado["id_aposta"];
if($idAposta == $idAnt) {
$x[$n] = array(
"timeApostado" => $tipo_aposta,
"partidaApostada" => $time
);
$n++;
} else {
$n = 0;
$x = array(
"valor_apostado" => $valor_apostado,
"valor_final" =>$valor_final,
"id_aposta" => $idAposta,
$n => array(
"timeApostado" => $tipo_aposta,
"partidaApostada" => $time
)
);
$array[$i]= $x;
$i++;
$n++;
}
$idAnt = $idAposta;
}