src/Kisma/Core/Utility/Scalar.php
public static function arraySort( &$arrayToSort, $columnsToSort = array() )
    {
        //	Convert to an array
        if ( !empty( $columnsToSort ) && !is_array( $columnsToSort ) )
        {
            $columnsToSort = array($columnsToSort);
        }

        //	Any fields?
        if ( !empty( $columnsToSort ) )
        {
            return usort(
                $arrayToSort,
                function ( $a, $b ) use ( $columnsToSort )
                {
                    $_result = null;

                    foreach ( $columnsToSort as $_column => $_order )
                    {
                        $_order = trim( strtolower( $_order ) );

                        if ( is_numeric( $_column ) && !static::in( $_order, 'asc', 'desc' ) )
                        {
                            $_column = $_order;
                            $_order = null;
                        }

                        if ( 'desc' == strtolower( $_order ) )
                        {
                            return strnatcmp( $b[$_column], $a[$_column] );
                        }

                        return strnatcmp( $a[$_column], $b[$_column] );
                    }
                }
            );
        }

        return false;
    }
public static function arraySort( &$arrayToSort, $columnsToSort = array() )
    {
        //	Convert to an array
        if ( !empty( $columnsToSort ) && !is_array( $columnsToSort ) )
        {
            $columnsToSort = array($columnsToSort);
        }

        //	Any fields?
        if ( !empty( $columnsToSort ) )
        {
            return usort(
                $arrayToSort,
                function ( $a, $b ) use ( $columnsToSort )
                {
                    $_result = null;

                    foreach ( $columnsToSort as $_column => $_order )
                    {
                        $_order = trim( strtolower( $_order ) );

                        if ( is_numeric( $_column ) && !static::in( $_order, 'asc', 'desc' ) )
                        {
                            $_column = $_order;
                            $_order = null;
                        }

                        if ( 'desc' == strtolower( $_order ) )
                        {
                            return strnatcmp( $b[$_column], $a[$_column] );
                        }

                        return strnatcmp( $a[$_column], $b[$_column] );
                    }
                }
            );
        }

        return false;
    }
public static function arraySort ( & $ arrayToSort , $ columnsToSort = array ( ) ) { //	Convert to an array if ( ! empty ( $ columnsToSort ) && ! is_array ( $ columnsToSort ) ) { $ columnsToSort = array ( $ columnsToSort ) ; } //	Any fields? if ( ! empty ( $ columnsToSort ) ) { return usort ( $ arrayToSort , function ( $ a , $ b ) use ( $ columnsToSort ) { $ _result = null ; foreach ( $ columnsToSort as $ _column => $ _order ) { $ _order = trim ( strtolower ( $ _order ) ) ; if ( is_numeric ( $ _column ) && ! static :: in ( $ _order , 'asc' , 'desc' ) ) { $ _column = $ _order ; $ _order = null ; } if ( 'desc' == strtolower ( $ _order ) ) { return strnatcmp ( $ b [ $ _column ] , $ a [ $ _column ] ) ; } return strnatcmp ( $ a [ $ _column ] , $ b [ $ _column ] ) ; } } ) ; } return false ; }
Generic array sorter

To sort a column in descending order, assign 'desc' to the column's value in the defining array:

$_columnsToSort = array(
'date' => 'desc',
'lastName' => 'asc',
'firstName' => 'asc',
);

@param array $arrayToSort
@param array $columnsToSort Array of columns in $arrayToSort to sort.

@return boolean
Generic array sorter