简体   繁体   English

如何从 ldap_get_entries 数组中提取条目

[英]How to pull entries out of ldap_get_entries array

I am trying to get a list of users in a Active Directory group using php ldap_get_entries.我正在尝试使用 php ldap_get_entries 获取 Active Directory 组中的用户列表。 I am able to connect to the ldap server and bind without a problem.我能够连接到 ldap 服务器并毫无问题地绑定。 This issue I have is the result I get from the array when using ldap_get_entires .我遇到的这个问题是我在使用ldap_get_entires时从数组中得到的结果。 Here is what I am using to get the data from the group:这是我用来从组中获取数据的方法:

$result = ldap_search($ldapConn, $ldaptree, "(member=*"),array('member'));
$data = ldap_get_entries($ldapConn, $result);
print_r($data);

What I get is this:我得到的是:

Array([count] => 1 [0] => Array([member] => Array([count => 3 [0] => CN=Mike Jones,CN=Users,DC=DOMAIN,DC=NET [1] => CN=Van Smith,CN=Users,DC=DOMAIN,DC=NET [2] => CN=Jane Doe,CN=Users,DC=DOMAIN,DC=NET) [0] => member[count] => 1 [dn] => CN=Cool Guys,CN=Users,DC=DOMAIN,DC=NET))

How do I pull out just the names from this array to look like this?我如何从这个数组中只提取名称以使其看起来像这样?

Mike Jones 
Van Smith 
Jane Doe

Thanks to @Thefourthbird for the suggestion.感谢@Thefourthbird 的建议。 He suggested I use the following to take out the names I need.他建议我使用以下内容来取出我需要的名称。

foreach ($array[0]["member"] as $key => $member) {
    if (is_int($key)) {
        $User[] = explode('=', explode(',', $member)[0])[1] . PHP_EOL;
    }
}

The only thing that was left to do was organize the data in alphabetical order.唯一剩下要做的就是按字母顺序组织数据。 I used a array_multisort function to do this.我使用array_multisort function 来执行此操作。

array_multisort($User, SORT_ASC);
foreach ($User as $key => $SortUser) {
    echo $SortUser;
}

Now all the names come out on their own line and in alphabetical order.现在所有的名字都出现在自己的行中并按字母顺序排列。

Jane Doe
Mike Jones 
Van Smith 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM