1
My problem is that my foreach only works when returning in XML, comes with more than one value in the array, but when it comes only 1, it doesn’t work.
The return in XML when comes more than 1 value would be like this:
<NewDataSet>
<HSONLINE>
<CONSIGNACAO id="1">
...Valores do array...
</CONSIGNACAO>
<CONSIGNACAO id="2">
...Valores do array...
</CONSIGNACAO>
</HSONLINE
</NewDataSet>
And when XML comes with only 1 value it would be like this:
<NewDataSet>
<HSONLINE>
<CONSIGNACAO id="1">
...Valores do array...
</CONSIGNACAO>
</HSONLINE
</NewDataSet>
This is my code in PHTML:
foreach($consignado as $registro){
//Verifico se a variavel não é um array
if(!is_array(current($retorno['HSONLINE']['CONSIGNACAO']))){
$registro = $retorno['HSONLINE']['CONSIGNACAO'];
}
//Declado as variaveis
$nomeBanco = $registro['NOME_BANCO'];
$dataInicio = $registro['DATA_INICIO'];
$parcelaTotal = $registro['PARCELA_TOTAL'];
$dataTermino = $registro['DATA_TERMINO'];
$exclusaoBanco = $registro['EXCLUIDO_BANCO'];
$valorEmprestado = $registro['VALOR_EMPRESTIMO'];
$valorParcela = $registro['VALOR_PARCELA'];
$contrato = $registro['CONTRATO'];
$fimDesconto = $registro['FIM_DESCONTO'];
$excluidoAPS = $registro['EXCLUIDO_APS'];
$codigoBanco = $registro['CODIGO_BANCO'];
$situacao = $registro['SITUACAO'];
$dataConsignacao = $registro['DATA_CONSIGNACAO'];
$banco = $registro['BANCO'];
$tipo = $registro['TIPO'];
$tipoCodigo = $registro['TIPO_CODIGO'];
$competenciaDesconto = $registro['COMPETENCIA_DESCONTO'];
$tipoDesconto = $registro['TIPO_DESCONTO'];
$parcelasAberto = $registro['PARCELAS_ABERTO'];
$saldoAproximado = $registro['SALDO_APROXIMADO'];
$dataAverbacao = $registro['DATA_AVERBACAO'];
$pintar="
<table class=\"table-custom\">
<tbody>
<tr>
<td class=\"banco2\">$nomeBanco</td>
<td class=\"tdCustom2\">$dataInicio</td>
<td class=\"tdCustom2\">$parcelaTotal</td>
<td class=\"tdCustom2\">$dataTermino</td>
<td class=\"tdCustom2\">$exclusaoBanco</td>
<td class=\"tdCustom2\">$valorEmprestado</td>
<td class=\"tdCustom2\">$valorParcela</td>
</tr>
<tr class=\"tr-esconder1\">
<td class=\"contrato2\">$contrato</td>
<td class=\"tdCustom2\">$fimDesconto</td>
<td class=\"tdCustom2\">$excluidoAPS</td>
<td class=\"tdCustom2\">$codigoBanco</td>
<td class=\"tdCustom2\">$situacao</td>
<td class=\"tdCustom2\">$dataConsignacao</td>
<td class=\"tdCustom2\">$banco</td>
</tr>
<tr class=\"tr-esconder1\">
<td class=\"contrato2\">$tipo</td>
<td class=\"tdCustom2\">$tipoCodigo</td>
<td class=\"tdCustom2\">$competenciaDesconto</td>
<td class=\"tdCustom2\">$tipoDesconto</td>
<td class=\"tdCustom2\">$parcelasAberto</td>
<td class=\"tdCustom2\">$saldoAproximado</td>
<td class=\"tdCustom2\">$dataAverbacao</td>
</tr>
<br/>
</tbody>
</table>";
$pintar = str_replace(">Array<", ">Não Informado<", $pintar);
echo $pintar;
//Aqui ele faz a verificação se não é um array e da o break
if(!is_array(current($retorno['HSONLINE']['CONSIGNACAO']))){
break;
}
}
The page layout looks like this, when XML comes with more than 1 CONSIGNACAO
And it gets like this when only one comes:
Thanks for your help!
There’s no missing one
>
after the</HSONLINE
?– Victor Stafusa
This was my mistake, but in the XML that I use is right
– Samuel Muzelli