Created
August 10, 2012 05:13
-
-
Save tadasuke/3311231 to your computer and use it in GitHub Desktop.
PHP usortで無名関数
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
$array = array( | |
array( | |
'name' => 'sato' | |
, 'sales' => 100 | |
) | |
, array( | |
'name' => 'suzuki' | |
, 'sales' => 200 | |
) | |
, array( | |
'name' => 'tanaka' | |
, 'sales' => 50 | |
) | |
); | |
usort( $array, function( $a, $b ) { | |
if ( $a['sales'] == $b['sales'] ) return 0; | |
return ( $a['sales'] > $b['sales'] ) ? 1 : -1; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment