How to build multivalue form elements using Form API
Suppose 'field_page_collection1' is the field collection for the 'page' content type having two text fields 'field_page_collection1_text1', 'field_page_collection1_text2'.

To attach or create field-collection item for node having node id 1.

&lt;?php
$node = node_load(1);
$field_collection_item = entity_create('field_collection_item', array('field_name' =&gt; 'field_page_collection1')); // Create new field collection item.
$field_collection_item-&gt;setHostEntity('node', $node); // Attach it to the node.
$field_collection_item-&gt;field_page_collection1_text1[LANGUAGE_NONE][0]['value'] = 'some value for text field 1'; // Fill value for field_page_collection1_text1.
$field_collection_item-&gt;field_page_collection1_text2[LANGUAGE_NONE][0]['value'] = 'some value for text field 2'; // Fill value for field_page_collection1_text2.
$field_collection_item-&gt;save(); // Save field-collection item.
?&gt;