src/anekdotes/Arr.php
public static function sortByKey($data, $sortKey, $sort_flags = SORT_ASC)
  {
      if (empty($data) or empty($sortKey)) {
          return $data;
      }

      $ordered = [];
      $i = 0;
      foreach ($data as $key => $value) {
          ++$i;
          $ordered[$value[$sortKey].'-'.$i] = $value;
      }

      switch ($sort_flags) {
      case SORT_ASC:
        ksort($ordered, SORT_NUMERIC);
      break;
      case SORT_DESC:
        krsort($ordered, SORT_NUMERIC);
      break;
    }

      return array_values($ordered);
  }
public static function sortByKey($data, $sortKey, $sort_flags = SORT_ASC)
  {
      if (empty($data) or empty($sortKey)) {
          return $data;
      }

      $ordered = [];
      $i = 0;
      foreach ($data as $key => $value) {
          ++$i;
          $ordered[$value[$sortKey].'-'.$i] = $value;
      }

      switch ($sort_flags) {
      case SORT_ASC:
        ksort($ordered, SORT_NUMERIC);
      break;
      case SORT_DESC:
        krsort($ordered, SORT_NUMERIC);
      break;
    }

      return array_values($ordered);
  }
public static function sortByKey ( $ data , $ sortKey , $ sort_flags = SORT_ASC ) { if ( empty ( $ data ) or empty ( $ sortKey ) ) { return $ data ; } $ ordered = [ ] ; $ i = 0 ; foreach ( $ data as $ key => $ value ) { ++ $ i ; $ ordered [ $ value [ $ sortKey ] . '-' . $ i ] = $ value ; } switch ( $ sort_flags ) { case SORT_ASC : ksort ( $ ordered , SORT_NUMERIC ) ; break ; case SORT_DESC : krsort ( $ ordered , SORT_NUMERIC ) ; break ; } return array_values ( $ ordered ) ; }
Sort the array by an object's key value.

@param   array   $data       The array to sort
@param   string  $sortKey    On which object's key the array must be sorted
@param   \enum   $sort_flags Either SORT_ASC or SORT_DESC. Defines if the sort is ascending or descending

@return  array               The ordered array
Sort the array by an object s key value .