$a = array(0=>\'a\',1=>\'b\',2=>\'c\', 3=>\'d\');
I want to change the order to be 3,2,0,1
:
$a = array(3=>\
function reorder_array(&$array, $new_order) {
$inverted = array_flip($new_order);
uksort($array, function($a, $b) use ($inverted) {
return $inverted[$a] > $inverted[$b];
});
}
$a = array(0=>'a',1=>'b',2=>'c', 3=>'d');
reorder_array($a, array(3, 2, 0, 1));
var_dump($a);
Result:
Array ( [3] => d [2] => c [0] => a [1] => b )