note 69386 deleted from function.array-multisort by cmb
| From: | cmb@php.net | Date: | Sun, 29 Sep 2019 07:45:29 +0000 |
| Subject: | note 69386 deleted from function.array-multisort by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212417@lists.php.net to get a copy of this message | ||
Note Submitter: ricardo
----
Hi,
Modded the function from KES,
goals:
- Object oriented
- string comparision using naturalordening
code:
<?
class HtmlTable{
var $sortorder;
var $rows;
//row adding stuf and constructor removed
function sort($sortorder){
if(is_array($sortorder)){
$this->sortorder=$sortorder;
usort($this->rows,array(&$this,'sort_compare'));
}
}
function sort_compare($a,$b){//sort function
$result=0;
foreach($this->sortorder as $key=>$value){
$result=strnatcmp($a[$key],$b[$key]);
if($result==0)continue;
if($value=='desc')$result=$result*-1;
break;
}
return $result;
}
}
?>