Question: I have a array which comes through an POST request from javascript/jquery. In php the array content is as follows:

```
[{"name":"Ta","def":"somestring"},{"name":"WSCall","def":"somestring"},{"name":"manual","def":"somestring"}]

```

How do I iterate over this array to get the keys and values?

When I do: `json_decode($_POST['shape_defs'])`

How do I iterate over this array. Doing `foreach` says: 

> 
> Invalid argument supplied for foreach()
> 
> 
>

Answer: 
While the (current) other two answers do get working code, they fail to address why you get the error you do.

```
$data = json_decode($j);
var_dump($data);

```

This will produce an *object*, with keys as properties. An object is not valid to be passed to `foreach` unless it implements `Traversable`.

What you need to do is:

```
$data = json_decode($j,true);

```

This will make objects be associative arrays instead, which are compatible with `foreach` and most likely the rest of your code.
When there's a definite number of children, you can use nested foreach-loops:

```
$json = '[{"name":"Ta","def":"somestring"},{"name":"WSCall","def":"somestring"},    {"name":"manual","def":"somestring"}]';
$decode = json_decode($json, true);

foreach ($decode as $k1 => $v1) {
    foreach ($v1 as $k2 => $v2) {
        echo "$k2: $v2, ";
    }
    echo "<br>";
}

```

It will output this:

```
name: Ta, def: somestring, <br>
name: WSCall, def: somestring, <br>
name: manual, def: somestring, <br>

```