I have an array:
$array = array('a' => 'val1', 'b' => 'val2', 'c' => 'val3', 'd' => 'val4');
How do I swap any two keys round so the array is in a different order? E.g. to produce this array:
$array = array('d' => 'val4', 'b' => 'val2', 'c' => 'val3', 'a' => 'val1');
Thanks :).
I thought there would be really simple answer by now, so I’ll throw mine in the pile:
This is swapping the first and last elements of the array, preserving keys. I thought you wanted
array_flip()originally, so hopefully I’ve understood correctly.Demo: http://codepad.org/eTok9WA6