示例#1
0
 /**
  * Sorting elements by key (key may be property, array key, or method)
  */
 public static function sortBy(&$sortingArray, $sortByKey, $orderAsc = true, $saveIndexes = false)
 {
     //
     //self::$sortingArray = null;
     self::$sortKey = $sortByKey;
     $function_name = '';
     self::$orderSort = $orderAsc ? 1 : -1;
     foreach ($sortingArray as $firstElem) {
         break;
     }
     if (is_array($firstElem)) {
         $function_name = 'UtilsHelper::compareByKey';
     }
     if (is_object($firstElem)) {
         if (method_exists($firstElem, $sortByKey)) {
             $function_name = 'UtilsHelper::compareByMethod';
         } else {
             $function_name = 'UtilsHelper::compareByProperty';
         }
     }
     if ($saveIndexes) {
         uasort($sortingArray, $function_name);
     } else {
         usort($sortingArray, $function_name);
     }
 }