Problemas ao Iterar array multidimensional
Olá!
Estou enfrentando problemas para iterar um array multidimensional.
O array possui uma estrutura assim: $meuArray['cliente']['tipoAtendimento']['subtipo'].
Array
(
[CLIENTE 1] => Array
(
[TIPO ATENDIMENTO 1] => Array
(
[OUTROS] => 14
[ELETRONICO] => 13
[TECNICO] => 21
[RRD] => 14
[TELEFONICO] => 15
)
[TIPO ATENDIMENTO 2] => Array
(
[PESSOAL] => 17
[TELEFONE] => 1373
)
)
[CLIENTE 2] => Array
(
[TIPO ATENDIMENTO 1] => Array
(
[OUTROS] => 14
[ELETRONICO] => 13
[TECNICO] => 21
[RRD] => 14
[TELEFONICO] => 15
)
[TIPO ATENDIMENTO 2] => Array
(
[PESSOAL] => 17
[TELEFONE] => 1373
)
)
)
Preciso iterar e inserir os dados em uma tabela desta forma:
<table align="center" border="1" cellpadding="1" cellspacing="1" style="background-color:#ffffcc;border-collapse:collapse;border:1px solid #ffcc00;width:50%;">
<thead>
<th width="105"><b class="fontcorpreta">Cliente</b></th>
<th width="100"><b class="fontcorpreta">Tipo Atend.</b></th>
<th width="100"><b class="fontcorpreta">Forma Atend.</b></th>
</thead> <tbody> <tr> <td colspan="1" rowspan="9">$meuArray['cliente']</td> <td colspan="1" rowspan="2" style="text-align: center; vertical-align: middle;">$meuArray['cliente']['tipoAtendimento']</td> <td>$meuArray['cliente']['tipoAtendimento']['subtipo']</td> </tr> <tr> <td>$meuArray['cliente']['tipoAtendimento']['subtipo']</td> </tr> <tr> <td colspan="1" rowspan="7" style="text-align: center; vertical-align: middle;">$meuArray['cliente']['tipoAtendimento']</td> <td>$meuArray['cliente']['tipoAtendimento']['subtipo']</td> </tr> <tr> <td>$meuArray['cliente']['tipoAtendimento']['subtipo']</td> </tr> <tr> <td>$meuArray['cliente']['tipoAtendimento']['subtipo']</td> </tr> <tr> <td>$meuArray['cliente']['tipoAtendimento']['subtipo']</td> </tr> <tr> <td>$meuArray['cliente']['tipoAtendimento']['subtipo']</td> </tr> <tr> <td>$meuArray['cliente']['tipoAtendimento']['subtipo']</td> </tr> <tr> <td>$meuArray['cliente']['tipoAtendimento']['subtipo']</td> </tr> </tbody> </table>
Segue uma imagem de como eu preciso estruturar a tabela: https://jsfiddle.net/fininhors/05L6k5fz/
Tentei iterar deste jeito mas não deu certo:
<table class="estilo_tabela marginauto">
<thead>
<tr>
<th width="105"><b class="fontcorpreta">Cliente</b></th>
<th width="100"><b class="fontcorpreta">Tipo Atend.</b></th>
<th width="100"><b class="fontcorpreta">Forma Atend.</b></th>
<th width="45"><b class="fontcorpreta">Parciais</b></th>
<th width="45"><b class="fontcorpreta">Total</b></th>
</tr>
<tr>
<td colspan="5"><hr width="100%"></td>
</tr>
</thead>
<tbody>
<?php foreach ((array)$_SESSION['SA_RELATORIO_RANKING'] as $cliente => $tipoAtend) {
foreach ((array)$tipoAtend as $tipo => $subTipo) {
foreach ((array)$subTipo as $chave => $valor) { ?>
<tr>
<td colspan="1" rowspan="9"><?php echo $cliente;?></td>
<td colspan="1" rowspan="2" style="text-align: center; vertical-align: middle;"><?php echo $tipo; ?></td>
<td><?php echo $_SESSION['SA_RELATORIO_RANKING'][$cliente][RA][RA-PESSOAL] ?></td>
</tr>
<tr>
<td><?php echo $_SESSION['SA_RELATORIO_RANKING'][$cliente][RA][RA-TELEFONE] ?></td>
</tr>
<tr>
<td colspan="1" rowspan="7" style="text-align: center; vertical-align: middle;"><?php echo $tipo; ?></td>
<td><?php echo $chave; ?></td>
</tr>
<tr>
<td><?php echo $chave; ?></td>
</tr>
<tr>
<td><?php echo $chave; ?></td>
</tr>
<tr>
<td><?php echo $chave; ?></td>
</tr>
<tr>
<td><?php echo $chave; ?></td>
</tr>
<tr>
<td><?php echo $chave; ?></td>
</tr>
<tr>
<td><?php echo $chave; ?></td>
</tr>
<?php }
}?>
<?php } ?>
</tbody>
</table>Discussão (0)
Carregando comentários...