src/Alg/Sort/MapList.php
public static function sortByMultipleColumns( $data, $orders )
	{
		$key		= array_shift( array_keys( $orders ) );						//  get first Column
		$direction	= $orders[$key];											//  get first Diection
		$orders		= array_slice( $orders, 1 );								//  remove Order from Order Map
		$list		= array();													//  prepare Index List
		foreach( $data as $entry )												//  iterate Data Array
			$list[$entry[$key]][]	= $entry;									//  index by Column Key

		if( $direction == self::DIRECTION_ASC )									//  ascending
			ksort( $list );														//  sort Index List
		else																	//  descending
			krsort( $list );													//  reverse sort Index List
		$array	= array();														//  prepare new Data Array
		foreach( $list as $entries )											//  iterate Index List
		{
			if( $orders && count( $entries ) > 1 )
				$entries	= self::sortByMultipleColumns( $entries, $orders );
			foreach( $entries as $entry)										//  ...
				$array[]	= $entry;											//  fill new Data Array
		}
		return $array;															//  return new Data Array
	}
public static function sortByMultipleColumns( $data, $orders )
	{
		$key		= array_shift( array_keys( $orders ) );						//  get first Column
		$direction	= $orders[$key];											//  get first Diection
		$orders		= array_slice( $orders, 1 );								//  remove Order from Order Map
		$list		= array();													//  prepare Index List
		foreach( $data as $entry )												//  iterate Data Array
			$list[$entry[$key]][]	= $entry;									//  index by Column Key

		if( $direction == self::DIRECTION_ASC )									//  ascending
			ksort( $list );														//  sort Index List
		else																	//  descending
			krsort( $list );													//  reverse sort Index List
		$array	= array();														//  prepare new Data Array
		foreach( $list as $entries )											//  iterate Index List
		{
			if( $orders && count( $entries ) > 1 )
				$entries	= self::sortByMultipleColumns( $entries, $orders );
			foreach( $entries as $entry)										//  ...
				$array[]	= $entry;											//  fill new Data Array
		}
		return $array;															//  return new Data Array
	}
public static function sortByMultipleColumns ( $ data , $ orders ) { $ key = array_shift ( array_keys ( $ orders ) ) ; //  get first Column $ direction = $ orders [ $ key ] ; //  get first Diection $ orders = array_slice ( $ orders , 1 ) ; //  remove Order from Order Map $ list = array ( ) ; //  prepare Index List foreach ( $ data as $ entry ) //  iterate Data Array $ list [ $ entry [ $ key ] ] [ ] = $ entry ; //  index by Column Key if ( $ direction == self :: DIRECTION_ASC ) //  ascending ksort ( $ list ) ; //  sort Index List else //  descending krsort ( $ list ) ; //  reverse sort Index List $ array = array ( ) ; //  prepare new Data Array foreach ( $ list as $ entries ) //  iterate Index List { if ( $ orders && count ( $ entries ) > 1 ) $ entries = self :: sortByMultipleColumns ( $ entries , $ orders ) ; foreach ( $ entries as $ entry ) //  ... $ array [ ] = $ entry ; //  fill new Data Array } return $ array ; //  return new Data Array }
Sorts a List of associative Arrays by several Columns and Directions.
@access		public
@static
@param		array		$data		List of associative Arrays
@param		string		$order		Map of Columns and their Directions (0 - ::DIRECTION_ASC | 1 - ::DIRECTION_DESC)
@return		array
Sorts a List of associative Arrays by several Columns and Directions .