Skip to content

Instantly share code, notes, and snippets.

@prionkor
Created June 9, 2014 04:52
Show Gist options
  • Save prionkor/052eca2ff89f25e0e0be to your computer and use it in GitHub Desktop.
Save prionkor/052eca2ff89f25e0e0be to your computer and use it in GitHub Desktop.
/**
* 7.Sort data function
* Allows you to sort the data by the variables set in the $_GET
* @return Mixed
*/
private function sort_data( $a, $b ) {
// Set defaults
$orderby = 'ID';
$order = 'asc';
// If orderby is set, use this as the sort column
if( !empty( $_GET['orderby'] ) ) $orderby = $_GET['orderby'];
// If order is set use this as the order
if( !empty( $_GET['order'] ) ) $order = $_GET['order'];
$result = strnatcmp( $a[$orderby], $b[$orderby] );
if( $order === 'asc' ) return $result;
return -$result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment