My friend, this is looking like university course evaluation activity ... but let's see what matters, the foreach
structure to go through this DESUNIFORME Array is:
foreach ( $array as $loja ) {
echo "<strong>Loja: {$loja['loja']} </strong><br>";
$itens = $loja[0];
if ( isset( $itens['produto'] ) ) {
echo "-Item: {$itens['produto']} <br>";
echo "-Qtd: {$itens['qtd']} <br><br>";
} else {
foreach ( $loja[0] as $key => $value ) {
echo "-Item: {$value['produto']} <br>";
echo "-Qtd: {$value['qtd']} <br><br>";
}
}
}
Note: I took the liberty of including some HTML tags, for better display ...
Ideally, you have a uniform structure in this Array to store the data, you will notice that there is a mixture of two-dimensional Arrays with numeric indexes and literal indexes, this is a confusion when you manipulate this data, which you will get very angry when it has many rows and columns ...
But as I know that it is not always possible to do the way we want, if it is possible you change the power structure of this Array I will leave a suggestion, see that reading is simpler too.
$array = array(
array(
'loja' => 'Loja1',
'itens' => array(
array(
'produto' => 'bolsa', 'qtd' => 1
),
array(
'produto' => 'bolsa 3', 'qtd' => 3
)
)
),
array(
'loja' => 'Loja2',
'itens' => array(
array(
'produto' => 'bolsa 2', 'qtd' => 2
)
)
)
);
foreach ( $array as $loja ) {
echo "<strong>Loja: {$loja['loja']} </strong><br>";
foreach ( $loja['itens'] as $itens ) {
echo "-Item: {$itens['produto']} <br>";
echo "-Qtd: {$itens['qtd']} <br><br>";
}
}
In this format, the hierarchy becomes a bit more standardized and simple.