How can I retrieve the profile2 fields selected in a custom module? I am totally new to entities in Drupal.  I have used the Profile2 module to add a few profile types.  This is displayed in the add/user screen as Customer.

After adding the profile type I manage the fields and add a new entry called cust with a field_id of field_cid.  This is setup as a list(text) and checkbox widget.

When I edit a user I have a checkbox list for Customer that can be selected by each user.  I have a custom module that I am trying to read the selected value by $user-&gt;uid from the profile2 field.

The idea is to retrieve the selected item in my module and format the return values to the user from a custom DB table.  Here is what I have tried and got results but cannot get all the values.

In my module using:

$profile = profile2_load_by_user($user-&gt;uid);$list = field_view_field('profile2', $profile['customer'], 'field_cid');print_r($list)


I get this result:

Array ( [#theme] =&gt; field [#weight] =&gt; 0 [#title] =&gt; cust [#access] =&gt; 1 [#label_display] =&gt; above [#view_mode] =&gt; _custom_display [#language] =&gt; und [#field_name] =&gt; field_cid [#field_type] =&gt; list_text [#field_translatable] =&gt; 0 [#entity_type] =&gt; profile2 [#bundle] =&gt; customer [#object] =&gt; Profile Object ( [pid] =&gt; 9 [type] =&gt; customer [label] =&gt; Customer [uid] =&gt; 1 [created] =&gt; 1409542969 [changed] =&gt; 1409545821 [entityType:protected] =&gt; profile2 [entityInfo:protected] =&gt; Array ( [label] =&gt; Profile [plural label] =&gt; Profiles [description] =&gt; Profile2 user profiles. [entity class] =&gt; Profile [controller class] =&gt; EntityAPIController [base table] =&gt; profile [fieldable] =&gt; 1 [view modes] =&gt; Array ( [account] =&gt; Array ( [label] =&gt; User account [custom settings] =&gt; ) ) [entity keys] =&gt; Array ( [id] =&gt; pid [bundle] =&gt; type [label] =&gt; label [revision] =&gt; ) [bundles] =&gt; Array ( [customer] =&gt; Array ( [label] =&gt; Customer [admin] =&gt; Array ( [path] =&gt; admin/structure/profiles/manage/%profile2_type [real path] =&gt; admin/structure/profiles/manage/customer [bundle argument] =&gt; 4 [access arguments] =&gt; Array ( [0] =&gt; administer profiles ) ) [rdf_mapping] =&gt; Array ( ) ) ) [bundle keys] =&gt; Array ( [bundle] =&gt; type ) [label callback] =&gt; entity_class_label [uri callback] =&gt; entity_class_uri [access callback] =&gt; profile2_access [module] =&gt; profile2 [metadata controller class] =&gt; Profile2MetadataController [static cache] =&gt; 1 [field cache] =&gt; 1 [load hook] =&gt; profile2_load [translation] =&gt; Array ( ) [schema_fields_sql] =&gt; Array ( [base table] =&gt; Array ( [0] =&gt; pid [1] =&gt; type [2] =&gt; uid [3] =&gt; label [4] =&gt; created [5] =&gt; changed ) ) [configuration] =&gt; ) [idKey:protected] =&gt; pid [nameKey:protected] =&gt; pid [statusKey:protected] =&gt; status [defaultLabel:protected] =&gt; [field_cid] =&gt; Array ( [und] =&gt; Array ( [0] =&gt; Array ( [value] =&gt; 1 ) [1] =&gt; Array ( [value] =&gt; 2 ) ) ) [field_test] =&gt; Array ( [und] =&gt; Array ( [0] =&gt; Array ( [value] =&gt; 3 ) ) ) [rdf_mapping] =&gt; Array ( ) ) [#items] =&gt; Array ( [0] =&gt; Array ( [value] =&gt; 1 ) [1] =&gt; Array ( [value] =&gt; 2 ) ) [#formatter] =&gt; list_default [0] =&gt; Array ( [#markup] =&gt; Disney ) [1] =&gt; Array ( [#markup] =&gt; Burger King ) )


I want the name in the last line [#markup] only returned to my function.  In the above output the returned values should be Disney and Burger King. 

How can I retrieve these values only?
Finally this is giving me the results I am after:

$profile = profile2_load_by_user($user-&gt;uid);
$customer = field_get_items('profile2', $profile['customer'], 'field_cid');
$key = array();
foreach($customer as $item=&gt;$value){
  $output = field_view_value('profile2', $profile['customer'], 'field_cid', $customer[$item]);
  $key[] = strip_tags(render($output));
}
foreach($key as $word) {
  echo $word . "&lt;/br&gt;";
}