Drupal 7 Extract Value from User Profile

I'm building a Drupal 7 module and I'd like to obtain the value of a custom user field (field_zipcode). How can I get the value and import into an array?
Who is Participating?
nanharbisonConnect With a Mentor Commented:
I didn't create this, I had found it one before:
//first load the global "user"
global $user;
//load the current users custom fields (you could get another uid's fields if you want)
$user_fields = user_load($user->uid);
//get the value you need from the array, by specifying the "system name" you used in drupal
$customfield = $user_fields->field_custom['und']['0']['value'];
//use the value
print  t("Custom field value is " . $customfield. ' ') ;
kjenneyAuthor Commented:
Perdect! I should have looked at this function ;)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.