Skip to content

Instantly share code, notes, and snippets.

@VSeryoga
Created April 12, 2017 08:55
Show Gist options
  • Save VSeryoga/d8fc3f20d7fadc0408b4685d31f19d91 to your computer and use it in GitHub Desktop.
Save VSeryoga/d8fc3f20d7fadc0408b4685d31f19d91 to your computer and use it in GitHub Desktop.
Сортировка многомерного массива по 2 знчениям
<?
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment