从Active Directory中选择“memberOf”信息

I've got a bit of a strange issue at the moment & I am literally out of ideas. I've written a PHP script which initially pulled all users information from AD, and displays this on my page. Out of 100+ users which are assigned to groups, I can only view the memberOf information in a var_dump for 4 of them. See code below:

$search_filter = "(&(sAMAccountName=my.username))";
    $attr = array("memberof");
    $result = ldap_search($ldap_connection, LDAP_DN, $search_filter, $attr);
    if (!empty($result)){
        $entries = ldap_get_entries($ldap_connection, $result);
    }

    if(!empty($entries)){
        $user_groups = array();
        foreach($entries[0]['memberof'] as $key => $value){
            $user_groups[] = $value;
        }
        array_shift($user_groups);
    }

    var_dump($user_groups);

Are there any restrictions on this field, or any reason why this attribute would only be showing for 4 users when it has been assigned for all users?

Any suggestions or help would be greatly appreciated.

MemberOf will contain a list (its a multi-valued attribute) of all groups that a user is a member of, with one exception: The user's primary group won't be in that list. So if the user is just a member of Domain Users, and that is by default also the user's primary group, then the 'MemberOf' attribute will not exist for that user. Add the user to another group, and you will see that group listed in MemberOf, just not Domain Users.

This assumes you have the security rights to read this attribute, but its usually open to nearly anyone.