php如何按另外一个数组重新排列自身?
------解决方案--------------------
- PHP code
function array_order(&$ar, $by) { asort($by); foreach($by as $k=>$v) { $r[$k] = $ar[$k]; } return $ar = $r; } $arr = array( 'a' => 'aa', 'b' => 'bb', 'c' => 'cc', ); $sort_by = array( 'a' => 2, 'b' => 3, 'c' => 1, ); array_order($arr, $sort_by); print_r($arr);
------解决方案--------------------
array_multisort($sort_by,SORT_ASC,$arr);
print_r($arr);