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: 
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>

```
```
$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 />";
 }
}

```