How to: Array of field collection items Sorry for being a little bit impudent, bit i would need someone to build an array into a code snippet. As I know nearly nothing about php coding, I managed to adept some code I found to get the urls of video files stored in field collection fields (one is for the .mp4 movie, otherone for the .webm version). So far, the code works well, but - here comes the problem - there is only the first value of each field collection field displayed. So, I Think i would need an array to regenerate the div container containing the  tag with the source paths for each value of the field collection, not only for the first one. I anybody can help me, I would be very, very thankful.... i am working on this since more than 6 hours now...

here is my code: 

// get node object
$node = node_load($nid);

// get field collections from node 
$field_html_5_video = field_get_items('node', $node, 'field_html_5_video');

// get all fields values if collection exists
if (!empty($field_html_5_video)){
    $field = field_view_value('node',$node, 'field_html_5_video', $field_html_5_video[0]);  
    foreach ($field['entity']['field_collection_item'] as $id =&gt; $field_collection){

        // load the field collection item entity
        $field_collection_item = field_collection_item_load($id);
        // wrap the entity and make it easier to get the values of fields
        $field_wrapper = entity_metadata_wrapper('field_collection_item', $field_collection_item);

        // all values from the field collection
        $field_video_mp4        = $field_wrapper-&gt;field_video_mp4-&gt;value();
        $field_video_webm        = $field_wrapper-&gt;field_video_webm-&gt;value(); // an array of image data
        $field_video_description  = $field_wrapper-&gt;field_video_description-&gt;value(); 

        // getting the video urls
        $video_url_mp4          = $field_video_mp4['uri'] ? file_create_url($field_video_mp4['uri']) : '';
        $video_url_webm          = $field_video_webm['uri'] ? file_create_url($field_video_webm['uri']) : '';


        print '&lt;div class="singleswipe"&gt;';
        print '&lt;span&gt;';
        print '&lt;span class="inner"&gt;';
        print '&lt;video width="100%" controls&gt;';
        print '&lt;source src="' .$video_url_mp4. '" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\'&gt;';
        print '&lt;source src="' .$video_url_webm. '" type=\'video/webm; codecs="vp8, vorbis"\'&gt;';

        print '&lt;/video&gt;';
        print '&lt;/span&gt;&lt;/span&gt;';
        print '&lt;span class="datainfo"&gt;' .$field_video_description. '&lt;/span&gt;';
        print '&lt;/div&gt;';
    }
}
As per @Andrew comment, instead what you have try printing your HTML start a var outside your foreach and then:

$template .= '&lt;html&gt;';


adding to it, then print it out after your foreach has finished looping. 

In addition make an array outside the foreach, e.g.:

$newarray = array();


Try not using the entity_metadata_wrapper, as it seems like an extra layer of stuff to deal with.