我如何排序" award_year"所有其他密钥都将遵循排序顺序。所有关键名称除了" award_year"名称和总密钥也会有所不同?
array(7) {
["award_year"]=>
array(2) {
[0]=>
string(7) "1999-01"
[1]=>
string(7) "2010-02"
}
["award_title_user"]=>
array(2) {
[0]=>
string(1) "2"
[1]=>
string(2) "tt"
}
["award_description_user"]=>
array(2) {
[0]=>
string(1) "2"
[1]=>
string(3) "ddd"
}
["award_title_lang1"]=>
array(2) {
[0]=>
string(2) "ms"
[1]=>
string(3) "ms2"
}
["award_description_lang1"]=>
array(2) {
[0]=>
string(2) "ms"
[1]=>
string(3) "ms2"
}
}
请建议。
答案 0 :(得分:0)
可能不是最快的方式,但是:
sort($arrayin['award_year']);
$arrayout = array();
foreach( $arrayin["award_year"] as $key => $value ){
array_push($arrayout['award_year'], $array_in['award_year'][$key]);
array_push($arrayout['award_title_user'], $array_in['award_title_user'][$key]);
//etc
}
答案 1 :(得分:0)
for PHP 5.3:
//Sample Multi-dimensional Array ($myArray)
Array
(
[0] => Array
(
[award_year] => 2012
[award_title_user] => test2
)
[1] => Array
(
[award_year] => 2011
[award_title_user] => test1
)
)
usort($myArray, function($a, $b) {
return $a['award_year'] - $b['award_year'];
});
print_r($myArray);