Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Edelco's avatar

Laravel itterate through arrays in an array

I have the following dd from a API query:

array:22 [▼
  0 => array:3 [▼
    0 => {#436 ▼
      +"applicationInstance": "_definst_"
      +"name": "myAmsterdam"
      +"sourceIp": "rtmp://xx.xx.xx.xx:{portnumber}"
      +"isRecordingSet": false
      +"isStreamManagerStream": false
      +"isPublishedToVOD": false
      +"isConnected": true
      +"isPTZEnabled": false
      +"ptzPollingInterval": 2000
      +"ptzPollingIntervalMinimum": 1000
    }
    1 => {#418 ▶}
    2 => {#409 ▶}
  ]
  1 => []
  2 => []
  3 => []
  4 => array:3 [▶]
  5 => []
    ]

How will I be able to itterate over this so I can call the data from "name" and "isConnected" ?

0 likes
3 replies
nadj's avatar

Maybe a nested foreach?

foreach($apiResponse as $items) {
    if($items) {
        foreach($items as $subitem) {
            dd($subitem);
        }
    }
}
Edelco's avatar

@nadj

    @foreach($data as $items)
        @if($items)
                @foreach($items as $subitem)
                    {{ dd($subitem) }}
                @endforeach
        @endif
    @endforeach 

this returns an empty array in the blade view.

nadj's avatar

Check what is in $items variable in the first foreach.

@foreach($data as $items)
    dd($items);
        @if($items)
                @foreach($items as $subitem)
                    {{ dd($subitem) }}
                @endforeach
        @endif
    @endforeach 

Please or to participate in this conversation.