array_flip(): Can only flip STRING and INTEGER values with nested Field collection I'm getting the error Warning: array_flip(): Can only flip STRING and INTEGER values! in EntityAPIController-&gt;load() when using a field collection in another field collection.

Is this a bug in Field collection or the way I load the entities?
Either way: How can I solve the warning?

Here's a simplified version of how I load my entities and sub-entities:

foreach ($node-&gt;field_chapter[$language] as $chapter) { 
    $items = entity_load('field_collection_item', $chapter);
    foreach ($items as $item) {
        //Some echo's from fields in $item
        foreach ($item-&gt;field_paragraph as $paragraphItem) {
            $paragraphs = entity_load('field_collection_item', $paragraphItem);
            foreach ($paragraphs as $paragraph) {
            //Some echos in paragraph
            }
        }
    }
}
The problem is with your code.

You need to pass entity_load an array of entity IDs but the structure of a field on an entity is not just an array of IDs.

$item-&gt;field_paragraph is an array of field items and field items can come in many different structures based on the type of field.
Then there is also the ability to have different languages so the language is part of the structure.

The basic structure is like this:

$entity-&gt;field_name['language code'][delta]['column_name']


I think for field collections the entity id is stored in the "value" column so you would access it like this (this assumes you aren't using multiple languages):

$item-&gt;field_paragraph[LANGUAGE_NONE][0]['value']


That would get you the entity ID of the first item for that field.

It is generally considered better though to use field_get_items() like this:

// Pass a lang code into field_get_items() if you have a multilingual site.
if ($chapter_items = field_get_items('field_collection_item', $node, 'field_chapter')) {
  $chapter_ids = array();
  foreach ($chapter_items as $chapter_item) {
    $chapter_ids[] = $chapter_item['value'];
  }
  $chapters = entity_load('field_collection_item', $chapter_ids);
  foreach ($chapters as $chapter) {
    // Some echos from fields in $chapter.

    // Pass a lang code into field_get_items() if you have a multilingual site.
    if ($paragraph_items = field_get_items('field_collection_item', $chapter, 'field_paragraph')) {
      $paragraph_ids = array();
      foreach ($paragraph_items as $paragraph_item) {
        $paragraph_ids[] = $paragraph_item['value'];
      }
      $paragraphs = entity_load('field_collection_item', $paragraph_ids);
      foreach ($paragraphs as $paragraph) {
        // Some echos from fields in $paragraph.
      }
    }
  }
}


When you are using entities and fields like this it is a good idea to do some debugging to check out the actual structure of the data you're trying to use.