How to get an array of referenced entity ids from an entity reference field
As an alternative you can do it in one line with an array function instead of a loop:

$ids = array_column($entity-&gt;autoren-&gt;getValue(), 'target_id');


Edit: Use getValue() to only get the array of the field.