I have the following problem with my foreach since I am consuming a function that returns an associative array:
var_dump($respuesta);
array(7) { ["Codigo"]=> string(2) "28" ["NumeroCaja"]=> string(1) "2" ["Productos"]=> string(102) "[{"total": "1099", "descripcion": "Samsung"}, {"descripcion": "Galaxy A01"}, {"descripcion": "Negro"}]" ["Fecha"]=> string(10) "2022-03-29" ["Total"]=> string(4) "1099" ["Comision3%"]=> string(3) "500" ["Comision5%"]=> string(3) "600" }
and I try to iterate in my foreach as follows:
foreach ($respuesta as $val) {
echo $val['Codigo'];
}
and it throws me this error: Warning: Illegal string offset 'Codigo' , I understand that it must be because it is not associating well or does not know that $val has a "Codigo" association, so how can I assign it.