How to add fields wrapper in field preprocess
Based on the question I'm assuming you are asking for D7 ...

You should use a "container" for this. Something like this:

$element = $vars['element'];
if($vars['element']['#field_name'] == 'field_example') {
  foreach($vars['items'] as $key =&gt; $item) {
    // Do whatever you want...
  }
  $vars['items']['#type'] = 'container';
  $vars['items']['#attributes'] = array(
    'id' =&gt; "some-id",
    'class' =&gt; array(
      'some-class',
    ),
  );
}


See this other question for more details. Also, if you want to get a little more fancy you can look at using theme wrappers.