note 35531 modified in function.ldap-sort by danbrown

From: Date: Wed, 31 Mar 2010 16:23:46 +0000
Subject: note 35531 modified in function.ldap-sort by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167576@lists.php.net to get a copy of this message
Here's a simple LDAP sort function I wrote: <?php function sort_ldap_entries($e, $fld, $order) { for ($i = 0; $i < $e['count']; $i++) { for ($j = $i; $j < $e['count']; $j++) { $d = strcasecmp($e[$i][$fld][0], $e[$j][$fld][0]); switch ($order) { case 'A': if ($d > 0) swap($e, $i, $j); break; case 'D': if ($d < 0) swap($e, $i, $j); break; } } } return ($e); } function swap(&$ary, $i, $j) { $temp = $ary[$i]; $ary[$i] = $ary[$j]; $ary[$j] = $temp; } ?> so that it can be invoked like: <?php $entries = sort_ldap_entries($entries, 'mail', 'A'); // sort entries by ascending order of mail ?> where, `$entries' is the array returned by ldap_get_entries() function. This might be useful to those who still run older versions of PHP (<= 4.2.0) on their web servers :-) --was-- Here's a simple LDAP sort function I wrote: function sort_ldap_entries($e, $fld, $order) { for ($i = 0; $i < $e['count']; $i++) { for ($j = $i; $j < $e['count']; $j++) { $d = strcasecmp($e[$i][$fld][0], $e[$j][$fld][0]); switch ($order) { case 'A': if ($d > 0) swap($e, $i, $j); break; case 'D': if ($d < 0) swap($e, $i, $j); break; } } } return ($e); } function swap(&$ary, $i, $j) { $temp = $ary[$i]; $ary[$i] = $ary[$j]; $ary[$j] = $temp; } so that it can be invoked like: $entries = sort_ldap_entries($entries, 'mail', 'A'); // sort entries by ascending order of mail where, `$entries' is the array returned by ldap_get_entries() function. This might be useful to those who still run older versions of PHP (<= 4.2.0) on their web servers :-) http://php.net/manual/en/function.ldap-sort.php

« previous php.notes (#167576) next »