Drupal 8, save new fieldCollection items to user from a foreach loop doesn't work
Make sure you've configured the cardinality of the field collection foo as unlimited (or at least anything more than 1) under "Field settings".

Also double check the name that you are passing to the FieldCollectionItem::create() method. It shouldn't be the label name but the machine name of your foo field collection, which will probably be field_foo:

$field_collection_foo = FieldCollectionItem::create(
  array('field_name' =&gt; "field_foo")
);


This also applies to the subfield_data (in your field collection item):

$field_collection_foo-&gt;set("field_subfield_data", $data);