note 81447 added to function.ldap-sort
| From: | headley at my-mail dot ch | Date: | Thu, 28 Feb 2008 15:47:18 +0000 |
| Subject: | note 81447 added to function.ldap-sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136563@lists.php.net to get a copy of this message | ||
I've got extend the functionality of the last code.
Now you can sort the ldap-array with multiple sort-directions.
<?php
/*Scoped global*/
$LDAPSortOrder;
/*$array is the return from ldap_get_entries
$sortBy is an array of values to sort by in the order in
which to sort them
Example:
$sortBy=array('name' => 'ASC','givenname' =>
'DESC') ;
*/
function LDAPSort(&$array,$sortBy){
global $LDAPSortOrder;
$LDAPSortOrder = $sortBy;
usort($array,'ldapcompare');
}
/* The compare functions always check case insensitive*/
function ldapcompare($x,$y){
global $LDAPSortOrder;
/*
Loops through the items in order until a difference is found
*/
foreach($LDAPSortOrder as $ele => $direction){
if(strtolower($x[$ele][0]) == strtolower($y[$ele][0]))
continue;
else{
if(strtolower($x[$ele][0]) < strtolower($y[$ele][0])){
switch(strtoupper($direction)){
case 'ASC': return -1; break;
case 'DESC': return 1; break;
}
}
else{
switch(strtoupper($direction)){
case 'ASC': return 1; break;
case 'DESC': return -1; break;
}
}
}
}
return 0;
}
?>
----
Server IP: 217.13.201.10
Probable Submitter: 217.111.83.8
----
Manual Page -- http://www.php.net/manual/en/function.ldap-sort.php
Edit -- https://master.php.net/note/edit/81447
Del: integrated -- https://master.php.net/note/delete/81447/integrated
Del: useless -- https://master.php.net/note/delete/81447/useless
Del: bad code -- https://master.php.net/note/delete/81447/bad+code
Del: spam -- https://master.php.net/note/delete/81447/spam
Del: non-english -- https://master.php.net/note/delete/81447/non-english
Del: in docs -- https://master.php.net/note/delete/81447/in+docs
Del: other reasons-- https://master.php.net/note/delete/81447
Reject -- https://master.php.net/note/reject/81447
Search -- https://master.php.net/manage/user-notes.php