Skip to content

Instantly share code, notes, and snippets.

@heiglandreas
Created October 21, 2014 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heiglandreas/536f75cb06209093375b to your computer and use it in GitHub Desktop.
Save heiglandreas/536f75cb06209093375b to your computer and use it in GitHub Desktop.
Convert an LDAP-Result into a somewhat more usable array
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',
)
)
)
@vooxo
Copy link

vooxo commented Oct 27, 2017

You miss the closing bracket ')' in line 9.
Still it doesn't work properly, but thanks for the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment