Last active
May 30, 2019 14:34
-
-
Save eto4detak/49317edeeffff9876e919821bd655fdd to your computer and use it in GitHub Desktop.
php sort
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 sort_nested_arrays( $array, $args = array('votes' => 'desc') ){ | |
usort( $array, function( $a, $b ) use ( $args ){ | |
$res = 0; | |
$a = (object) $a; | |
$b = (object) $b; | |
foreach( $args as $k => $v ){ | |
if( $a->$k == $b->$k ) continue; | |
$res = ( $a->$k < $b->$k ) ? -1 : 1; | |
if( $v=='desc' ) $res= -$res; | |
break; | |
} | |
return $res; | |
} ); | |
return $array; | |
} | |
function sort_meta_index_start($a, $b) | |
{ | |
$start_sort_a = get_post_meta($a->ID, 'start_sort', 1); | |
$start_sort_b = get_post_meta($b->ID, 'start_sort', 1); | |
if(empty($start_sort_a)){ | |
$start_sort_a = 'zzzzzzzzzzzzz'; | |
} | |
if(empty($start_sort_b)){ | |
$start_sort_b = 'zzzzzzzzzzzzz'; | |
} | |
if ($start_sort_a == $start_sort_b) { | |
return 0; | |
} | |
return ($start_sort_a < $start_sort_b) ? -1 : 1; | |
} | |
usort($prop_selection->posts, "sort_meta_index_start"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment