Loop over Array and get the distinct ids

No, that’s because you are treating an array as an object and PHP doesn’t convert those types automatically. To get an individual element from an object you use:

$my_object->Element1;

To get an individual element from an array you use:

$my_array[Element1];

You can even nest arrays. So if you have $my_array, where each element is another array, you can get elementX from arrayY like this:

$my_array[arrayY][elementX];

In your case, apparently, you have an array, which holds an array, which holds objects, amounting to:

$my_array[arrayY][elementX]->componentZ