Created
June 9, 2014 04:52
-
-
Save prionkor/052eca2ff89f25e0e0be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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