Created
December 13, 2012 06:48
-
-
Save tadasuke/4274598 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
/** | |
* 配列の特定のキーを元にソートする | |
* @param array $array | |
* @param string $sortKey | |
* @param int $sortType | |
*/ | |
function sortArray( &$array, $sortKey, $sortType = SORT_ASC ) { | |
$tmpArray = array(); | |
foreach ( $array as $key => $row ) { | |
$tmpArray[$key] = $row[$sortKey]; | |
} | |
array_multisort( $tmpArray, $sortType, $array ); | |
unset( $tmpArray ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment