This note may be self-evident, but the functionality of ldap_sort threw off this sometime user of relational databases.
The following code will NOT do what you expect:
$ldap_attributes = array ( 'cn', 'o', 'mail' ) ;
$search_results = ldap_search ( $ldap_conn, 'dc=example,dc=org', '(objectclass=*)', 0, 500, 30 ) ;
ldap_sort ( $ldap_conn, $search_results, 'sn' ) ;
The entries will NOT be sorted by last name. Why not? Because LDAP doesn't function like a RDBMS; you cannot sort a result set on an arbitrary field, regardless of whether you "selected" it. You must always include the attribute by which you want to sort your entries among the requested attributes (add 'sn' to $ldap_attributes, in this case).
Hope this is helpful to some other folks who scratched their heads when they tried to sort entries and it didn't work out...