Created
October 21, 2014 20:17
-
-
Save heiglandreas/536f75cb06209093375b to your computer and use it in GitHub Desktop.
Convert an LDAP-Result into a somewhat more usable array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertLdapArray($resultArray) | |
{ | |
$attributes = array(); | |
foreach ($resultArray as $key => $value) { | |
if (! is_String($key)) { | |
continue; | |
} | |
// This is an integer key | |
if (! isset($resultArray[$value]) { | |
$resultArray[$value] = array(); | |
} | |
$attributes[$value] = $resultArray[$value]; | |
} | |
return $attributes; | |
} | |
$ldapResult = ldap_get_entries($con); | |
$entries = array(); | |
for ($i = 0; $i < $ldapResult['count']; $i++) { | |
$entries[] = convertLdapArray($ldapResult[$i]); | |
} | |
// $ldapResult now contains something like the following: | |
array( | |
array( | |
'first-name' => array( | |
'Jon', | |
'David' | |
), | |
'last-name' => array( | |
'Doe, | |
), | |
'uid' => array( | |
'jdoe', | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You miss the closing bracket ')' in line 9.
Still it doesn't work properly, but thanks for the idea.