In php, I would like to have the ability to re-order an associative array by moving elements to certain positions in the array. Not necessary a sort, just a re-ordering of
i made a function based on one answer here. it takes the array of assoc array to be sorted, plus array of keys in which it should be resorted
// $data = array of assoc array
// $newKeysOrder = array("c","a","b");
function resort_assoc_array_by_keys($data, $newKeysOrder) {
foreach($data as $v) {
$out = [];
foreach($newKeysOrder as $k) {
$out[$k] = $v[$k];
}
$new[] = $out;
}
return $new;
}