]> git.nbdom.net Git - nb.git/commitdiff
/opt/nb/lib/php/nb.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 13 Jul 2019 03:29:37 +0000 (04:29 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 13 Jul 2019 03:29:37 +0000 (04:29 +0100)
lib/php/nb.php

index 7244d46fb19dce4bc025139fbe10360aaaebf1ec..3a66932ec324737b91136a803de8997bf231193e 100644 (file)
@@ -582,7 +582,8 @@ class NB {
        }
 
        public static function hksort(&$h,$k,$get_first=false) {
-               uasort($h,create_function('$a,$b','$a_=isset($a["'.$k.'"])?$a["'.$k.'"]:-1;$b_=isset($b["'.$k.'"])?$b["'.$k.'"]:-1; return($b_-$a_);'));
+# NB 13.07.19          uasort($h,create_function('$a,$b','$a_=isset($a["'.$k.'"])?$a["'.$k.'"]:-1;$b_=isset($b["'.$k.'"])?$b["'.$k.'"]:-1; return($b_-$a_);'));
+               uasort($h,function($a,$b) use($k) {$a_=isset($a["'.$k.'"])?$a["'.$k.'"]:-1;$b_=isset($b["'.$k.'"])?$b["'.$k.'"]:-1; return($b_-$a_);});
                if ($get_first) {
                        $first = self::ar_first($h);
                        if ($get_first !== true) return $first[$get_first];
@@ -599,55 +600,6 @@ class NB {
                if (self::php_cli()) return file_write("php://stderr",$msg);
                echo($msg);
        }
-       /*
-       public static function ar_sort(&$ary, $clause, $ascending = true) {
-               $clause = str_ireplace('order by', '', $clause);
-               $clause = preg_replace('/\s+/', ' ', $clause);
-               $keys = explode(',', $clause);
-               $dirMap = array('desc' => 1, 'asc' => -1);
-               $def = $ascending ? -1 : 1;
-
-               $keyAry = array();
-               $dirAry = array();
-               foreach($keys as $key) {
-                               $key = explode(' ', trim($key));
-                               $keyAry[] = trim($key[0]);
-                               if(isset($key[1])) {
-                                               $dir = strtolower(trim($key[1]));
-                                               $dirAry[] = $dirMap[$dir] ? $dirMap[$dir] : $def;
-                               } else {
-                                               $dirAry[] = $def;
-                               }
-               }
-
-               $fnBody = '';
-               for($i = count($keyAry) - 1; $i >= 0; $i--) {
-                               $k = $keyAry[$i];
-                               $t = $dirAry[$i];
-                               $f = -1 * $t;
-                               $aStr = '$a[\''.$k.'\']';
-                               $bStr = '$b[\''.$k.'\']';
-                               if(strpos($k, '(') !== false) {
-                                               $aStr = '$a->'.$k;
-                                               $bStr = '$b->'.$k;
-                               }
-
-                               if($fnBody == '') {
-                                               $fnBody .= "if({$aStr} == {$bStr}) { return 0; }\n";
-                                               $fnBody .= "return ({$aStr} < {$bStr}) ? {$t} : {$f};\n";               
-                               } else {
-                                               $fnBody = "if({$aStr} == {$bStr}) {\n" . $fnBody;
-                                               $fnBody .= "}\n";
-                                               $fnBody .= "return ({$aStr} < {$bStr}) ? {$t} : {$f};\n";
-                               }
-               }
-
-               if($fnBody) {
-                               $sortFn = create_function('$a,$b', $fnBody);
-                               usort($ary, $sortFn);       
-               }
-       }
-       */
 
        public static function php_cli() {
 # NB 05.03.16 define('NB_CLI', PHP_SAPI === 'cli');