Re: LDAP sorting

From: Date: Fri, 30 Nov 2001 09:17:06 +0000
Subject: Re: LDAP sorting
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-76165@lists.php.net to get a copy of this message
The LDAP sorting code I posted a couple of days ago was a bit lacking. Here's a function that should work: function myldap_sort($data, $attr) { // -1 because of the count entry echo "#", $n = count($data) - 1; for ($i=0; $i<$n; $i++) { $a[$i]=$data[$i][$attr][0]; } asort($a); reset($a); for ($j=0; list($i,) = each($a); $j++) { $sorted[$j] = $data[$i]; } return $sorted; } It's not fast, but should work. Example usage: $info = ldap_get_entries($ds, $sr); $sorted = myldap_sort($info, "cn"); It assumes that the attribute specified is present in all the entries, and only uses the first value of the attribute. Stig

« previous php.general (#76165) next »