mark: USORT mit variablem Key

Beitrag lesen

Hab für mich folgende Lösung gefunden :

function usort_comparison($obj, $method, $key) {  
    $usorter = &new Usort($obj, $method, $key);  
    return array($usorter, "sort");  
}  
  
class Usort {  
    function __construct($obj, $method, $key) {  
        $this->obj = $obj;  
        $this->method = $method;  
        $this->key = $key;  
  
    }  
  
    function sort($a, $b) {  
        return call_user_func_array(array($this->obj, $this->method), array($a, $b, $this->key));  
    }  
  
    function cmp_by_name($a, $b, $key) {  
         return strcasecmp($a[$key], $b[$key]);  
    }  
}  
  
// Funktions Aufruf :  
usort($srtarr, usort_comparison("Usort", $meth, $key));