note 94245 deleted from function.ldap-search by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 11:17:56 +0000 |
| Subject: | note 94245 deleted from function.ldap-search by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197089@lists.php.net to get a copy of this message | ||
Note Submitter: eugene at hutorny dot in dot ua
----
This function accepts LDAP search results and return a flat table (2-d array) with search results.
<?php
/*
* This function returns flat table out of search results
* $ad - a valid connection to Active Directory (returned by ldap_connect)
* $sr - a search result (returned by ldap_search)
* $key- an attribute name to be used as the key in the resulting array
* Returns 2-d array as the following:
* return_value["keyfieldvalue"]["attributename"] = "attribute
value"; // entries with key filed present
* return_value[i]["attributename"] = "attribute value"; // entries with key
fields missing
*/
function ldap_flatresults($ad,$sr,$key=false) {
for ($entry=ldap_first_entry($ad,$sr);
$entry!=false;
$entry=ldap_next_entry($ad,$entry)) {
$user = array();
$attributes = ldap_get_attributes($ad,$entry);
for($i=$attributes['count'];$i-- >0;) {
$user[strtolower($attributes[$i])] = $attributes[$attributes[$i]][0];
}
if( $key && $user[$key] )
$users[strtolower($user[$key])] = $user;
else
$users[] = $user;
}
return $users;
}
?>