I have not used ldap, but since it is a directory access protocol, then I assume the values you are getting are actually resource identifiers, and not strings, which would explain the results you are getting. The if statement never executes. Try casting them to strings. and just get rid of the if statement.
function EntryCompare($a,$b)
{
$sortfield = "cn";
$a =(string)$a[$sortfield];
$b = (string)$b[$sortfield];
$a = strtolower($a);
$b = strtolower($b);
if ($a==$b){
return 0;
}
if ($a > $b) {
return 1;
}
return -1;
}
Or if you prefer use settype($a,"string"), settype($b,"string");
That's some pretty hacked up code, but it should work, and give you something to work with. You can make something a bit more robust.