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.
```
$j= '[{"name":"Ta","def":"somestring"},{"name":"WSCall","def":"somestring"},{"name":"manual","def":"somestring"}]';

$data = json_decode($j,true);

foreach($data as $key=>$val){
 foreach($val as $k=>$v){
   echo "Key :".$k."  Value :".$v."<br />";
 }
}

```