Edit user profile form
(upon writing back and forth, the solution to this problem is listed underneath Edit 2)

not sure where exactly you are stuck. are you asking how to check which taxonomy term they have assigned in a field, or how to show/hide fields?

if you already have access to the taxonomy term id and you need to further check the content of the taxonomy term, you can assign that id to a variable like$tid, and then do something like this:

$myfield_term = entity_load('taxonomy_term',array($tid))[$tid];


I find myself doing this a bunch of times, because of the way I use taxonomy terms.
this gives you an object with all the content of the taxonomy term.
if you wanna fetch information out of it, keep in mind that php uses a different approach for objects than for arrays.
so if you need the title value, instead of doing $myfield_term['title'], you need to do $myfield_term-&gt;title



EDIT 1:

can you please show us what the structure of the array looks like?
this can be done in various ways. drupal has its own technique of printing arrays (I believe it's caled devel or something), but I still prefer the good old native php way via print_r.

how I'd do it:


assign the array to a value, e.g. $user_apartments
then in the next line add print_r($user_apartments);
switch back to your browser, right click > view page source (may vary depending on your browser, this would be Chrome)


somewhere at the beginning or further down the code (depending on the file that executed the print_r command) should be a printed list of an array, that may look something like this:

Array
(
[0] =&gt; 4
[2] =&gt; 11
[3] =&gt; 28
[4] =&gt; ...
)


but it may as well be more complicated than this, if for example it not only lists the term IDs but all the content of the terms as well.


now just grab it and past a part of it here please (if it is a huge list, no need to post the repetitive part)


the way the print_r command works is it takes the object that you feed into it and displays the content in a more human-readable manner, giving you an insight of its structure, whether something is an object, an array, what else it contains etc.

so depending on what this array looks like, we will need to use a different approach on checking the array for your specific ID, this is why I am asking for an insight of the array we want to check.



EDIT 2:

so upon looking at the structure of the array, this is how you check for your term ID:
the array that we need to look at is ...['field_affiliation']['und']. you can (optionally) assign it to a variable, e.g. $field_affiliation, and then do something like this:

$hasDepartment28 = false;
foreach( $field_affiliation as $thisTerm ) {
    if( $thisTerm['tid'] == 28 ) {
        $hasDepartment28 = true;
        break;
    }
}


then, where- and whenever needed, you can simply check by doing

if( $hasDepartment28 ) {
    // do..
}


and here is how it works:


$hasDepartment28: we declare a boolean, and we say by default the department with the term id 28 is not listed
using foreach, we loop through every entry that is listed in the taxonomy term array we named $field_affiliation and every time we assign current entry to the variable name $term
now, as we could see in the structure of the array, what we want to look for is the 'tid' key of every entry
we compare it with the ID you mentioned in the comment below, and if we have a match, we set $hasDepartment28 to TRUE
and via break; we stop the current foreach. since we found what we were looking for, there is no need to loop through any other entry in the array that may come after it
if we found no entry at all where the tid equals 28, the boolean we set earlier will still equal FALSE


let me know if it worked!

keep in mind all the variable names are arbitrary and you should use whatever describes the variable best.

one last thing I'd add is if you were delete and re-create that term entry, you'd have to update this code and check for a different Term ID. perhaps a more readable and future-proof approach would be to check inside the foreach loop for something like:

if( $thisTerm['taxonomy_term']-&gt;name == 'Apartment A' ) { ... }


but this in return only works if the [taxonomy_term] gets loaded into your array for every entry. chances are only the first entry has all the term content, but based on the array you submitted I cannot tell you if this is the case. if you wanna stick to this approach though, this is exactly where drupal's entity_load function becomes super useful!