Just to note , this JSON is in an invalid format:
{
"result":[
{
“COD”:[10,3,4,11,1],
"DESCRICAO”:[mouse,teclado,monitor,webcam,celular],
"ESTOQUE”:[10,2,5,1,0],
"QUANT_UNID":[ UN,UN,UN,UN,CX]
}
]
}
Correct it first, it should look like this:
{
"result":[
{
"COD":[10,3,4,11,1],
"DESCRICAO":["mouse", "teclado", "monitor", "webcam", "celular" ],
"ESTOQUE":[10,2,5,1,0],
"QUANT_UNID":[ "UN", "UN", "UN", "UN", "CX" ]
}
]
}
After correcting (I assume it is dynamic) just use for
if all items have the same amount:
<?php
$json = ' {
"result":[
{
"COD":[10,3,4,11,1],
"DESCRICAO":["mouse", "teclado", "monitor", "webcam", "celular" ],
"ESTOQUE":[10,2,5,1,0],
"QUANT_UNID":[ "UN", "UN", "UN", "UN", "CX" ]
}
]
}';
$parsed = json_decode($json);
$results = $parsed->result;
foreach ($results as $item) {
$cod = $item->COD;
$qtd = $item->QUANT_UNID;
$estoque = $item->ESTOQUE;
$descricao = $item->DESCRICAO;
$j = count($cod);
for ($i = 0; $i < $j; $i++) {
echo $cod[$i], ' ';
echo $descricao[$i], ' ';
echo $qtd[$i], ' ';
echo $estoque[$i], '<br>';
}
}
If it's an HTML table:
for ($i = 0; $i < $j; $i++) {
echo '<tr>';
echo '<td>', $cod[$i], '</td>';
echo '<td>', $descricao[$i], '</td>';
echo '<td>', $qtd[$i], '</td>';
echo '<td>', $estoque[$i], '</td>';
echo '</tr>';
}
In case I used foreach
because I suppose that results can receive multiple data, like:
"result":[
{
"COD": ...,
"DESCRICAO": ...,
"ESTOQUE": ...,
"QUANT_UNID": ...
},
{
"COD": ...,
"DESCRICAO": ...,
"ESTOQUE": ...,
"QUANT_UNID": ...
},
{
"COD": ...,
"DESCRICAO": ...,
"ESTOQUE": ...,
"QUANT_UNID": ...
},
]