Iterating over associative array in PHP

I have an array $pedidos which I fill by:

$pedido[$nombreProducto['nombre']] = $cantidad;

So, when U try to iterate over it with this loop:

foreach ($pedidos as $key => $value) {
    echo $key."-->".$value;
}

I'm getting the error log message:

Invalid argument supplied for foreach()

How should I iterate over it?

Your array is called $pedido change the for each with this:

foreach ($pedido as $key => $value) {
    echo $key."-->".$value;
}

In foreach you have $pedidos, but you are filling array $pedido

Related Articles
You Might Also Like