mergeSort() public static method

http://at2.php.net/manual/en/function.usort.php#38827
public static mergeSort ( &$array, Closure $callback )
$callback Closure
Example #1
0
 /**
  * Process the sorting, also break sorting.
  *
  * @param array $table
  * @param Config $config
  *
  * @return array
  */
 private function processSort(array $table, Config $config)
 {
     if ($config['sort']) {
         $cols = array_reverse($config['sort']);
         foreach ($cols as $colName => $direction) {
             Sort::mergeSort($table, function ($elementA, $elementB) use($colName, $direction) {
                 if ($elementA[$colName] == $elementB[$colName]) {
                     return 0;
                 }
                 if ($direction === 'asc') {
                     return $elementA[$colName] < $elementB[$colName] ? -1 : 1;
                 }
                 return $elementA[$colName] > $elementB[$colName] ? -1 : 1;
             });
         }
     }
     if ($config['break']) {
         foreach ($config['break'] as $colName) {
             Sort::mergeSort($table, function ($elementA, $elementB) use($colName) {
                 if ($elementA[$colName] == $elementB[$colName]) {
                     return 0;
                 }
                 return $elementA[$colName] < $elementB[$colName] ? -1 : 1;
             });
         }
     }
     return $table;
 }