Last active
August 29, 2015 14:04
-
-
Save phplaw/f392efe3c3c7ff61f064 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
function pr($var) { echo '<pre>' .print_r($var, true). '</pre>'; } | |
$array = array( | |
(object) array('title'=>'a','ordering'=>2), | |
(object) array('title'=>'x','ordering'=>0), | |
(object) array('title'=>'r','ordering'=>4), | |
(object) array('title'=>'b','ordering'=>21), | |
(object) array('title'=>'b1','ordering'=>21), | |
(object) array('title'=>'q','ordering'=>6), | |
(object) array('title'=>'o','ordering'=>7), | |
(object) array('title'=>'n','ordering'=>9), | |
(object) array('title'=>'z','ordering'=>1), | |
(object) array('title'=>'m','ordering'=>22), | |
(object) array('title'=>'a.1','ordering'=>2), | |
); | |
function fn_sort_asc($a, $b) { | |
return $a->ordering - $b->ordering; | |
//return $a->ordering > $b->ordering; | |
//return strtolower($a['name']) > strtolower($b['name']); | |
//if ($a->ordering == $b->ordering ) { return 0; } // this will place item under to top instead of | |
if ($a->ordering == $b->ordering ) { return 1; } | |
return $a->ordering > $b->ordering ? 1 : -1; | |
} | |
pr($array); | |
uasort($array, 'fn_sort_asc'); | |
pr($array); | |
// k9 ga qua =)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment