Question: I am pulling data from a json file and I get results no problem but I a only get 1 result. So when I do a foreach loop I get no results.

**json results:**

```
{
  "channels": [
    {
      "position": 4,
      "id": "901",
      "name": "Away"
    },
    {
      "position": 0,
      "id": "900",
      "name": "General"
    },
    {
      "position": 1,
      "id": "889",
      "name": "HQ"
    },
    {
      "position": 2,
      "id": "888",
      "name": "Base"
    }
  ],
}

```

I can echo out this:

```
echo $json_array['channels'][0]['position'];
echo $json_array['channels'][0]['id'];
echo $json_array['channels'][0]['name'];

```

But whatever I try I only get 1 result I do a foreach loop and it does nothing

```
foreach($json_array as $item) {

     echo $item['channels'][0]['position'];
     echo $item['channels'][0]['id'];
     echo $item['channels'][0]['name'];

 }

```

Am I missing something?

Answer: 
You are getting the value of first object only. `$json_array['channels']` is an array of objects, you need to loop over that objects. This should work:

```
foreach($json_array['channels'] as $item) {
    echo $item['position'];
    echo $item['id'];
    echo $item['name'];
}

```

To make it clear to understand, this is how it would work with a for loop:

```
for($index = 0; $index < count($json_array['channels']); $index++) {
    echo $json_array['channels'][$index]['position'];
    echo $json_array['channels'][$index]['id'];
    echo $json_array['channels'][$index]['name'];
}

```
You missing collection iteration

```
foreach($json_array['channels'] as $item) {
    echo $item['position'];
    echo $item['id'];
    echo $item['name'];
}

```