Created
April 12, 2017 08:55
-
-
Save VSeryoga/d8fc3f20d7fadc0408b4685d31f19d91 to your computer and use it in GitHub Desktop.
Сортировка многомерного массива по 2 знчениям
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
<? | |
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